Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between text/plain and string?

I am trying to send a Put request to an older Java back end. The path on the back end is

@PUT
@Path("/foo/bar")
@Consumes("text/plain")
public String someFunction(String ExpectedArgument){
//Unrelated logic
}

I'm trying to send a string from the front end using Javascript and Axios.

let someString = 'Example String'
axios.put('/foo/bar',someString).then(resp=>console.log(resp))

Unfortunately, when I try to do this, I'm receiving an HTTP 415 error for bad content type. Reviewing other, successful put requests that I've made, the only difference I've found is that this one has the "@Consumes("text/plain")" line in it. I can only conclude that there's some difference between what the java is expecting as text/plain and what I'm providing with a javascript string.

I would like to know what about my string is causing it to be rejected and how I can edit my code so that the back end will accept it.

like image 659
NegativeFriction Avatar asked Dec 05 '25 16:12

NegativeFriction


1 Answers

const headers = {
  'Content-Type': 'text/plain',
}
let someString = 'Example String'
axios.put('/foo/bar', someString, {
    headers: headers
  }).then(resp=>console.log(resp))
like image 138
Optional Avatar answered Dec 07 '25 05:12

Optional