I am getting error using IBM's Integrated Web Services (IWS) on the IBM i (a.k.a AS400) w/RPG and getting this message, when trying to test a RESTful web service to accept JSON as input media. When input media is ALL it works, but trying to use POST with input media JSON. BTW - I am new to all of this web stuff. Any help would be greatly appreciated.
HTTP/1.1 400 Bad Request
Date: Mon, 01 May 2017 14:19:41 GMT
Server: Apache
X-Powered-By: IBM i
Content-Length: 119
Connection: close
Content-Type: text/plain
com.ibm.as400.access.ExtendedIllegalArgumentException: javaValue ({ "pinname": "Cecil Jones" }
): Length is not valid.
When input media is ALL it works, because Content-Type: text/plain is accepted.
If you want deploy service as json service you should in request headers specify:
Content-Type : application/json
I have a project made from WebBroker REST, running as a service, I need to change theCotent-Type response to application/json and by default WebBroker REST brings me as a result the
Content-Type 'text/html; charset=ISO-8859-1'
I change the response by accessing the method
GetInvocationMetadata(True).ResponseContentType = 'application/json'
of the Data.DBXPlatform class, but it still does not resolve it it adds anotherContent-Type just below the current one.
This only happens only in WebBroker REST, if I create a project by DataSnap Server I usually get it. But I need WebBroker REST to access the information the client sends me.
Example of how to make the problem occur.
Create a Project from the DataSnap REST Application
In the ServerMethods class, do the same model.
uses System.StrUtils, Data.DBXPlatform;
function TServerMethods1.EchoString(Value: string): string;
begin
Result := Value;
GetInvocationMetadata.ResponseContentType := 'application/json';
end;
Example response Header.
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 25
Date: Tue, 10 Sep 2013 16:41:37 GMT
Pragma: dssession=542354.126073.592372,dssessionexpires=1200000
Content-Type: application/json
In New DataSnap WebBroker Application Wizard you have the option to create a separate Server Module. In the generated unit WebModuleUnit1.pas there is a variable WebModuleClass, which is a descendant of TWebModule. This WebModuleClass object has a public property Response of type TWebResponse, which gives you ability to set ContentType.
http://docwiki.embarcadero.com/Libraries/Berlin/en/Web.HTTPApp.TWebResponse.ContentType
I am trying to do a POST in jmeter with a json as the body data but I just get a 400 back. The URL I am sending to only accepts json. I have used the same curl in Postman and it worked just fine. I have tried putting the json in the parameters as a value with no name and that didnt work.
I am just trying to send {"uid":"jmtest","name":"newdevice"}.
Sorry I cant post more links.
The sampler result is
Thread Name: QA test 1-1
Sample Start: 2016-05-11 11:50:19 MDT
Load time: 86
Connect Time: 51
Latency: 86
Size in bytes: 282
Headers size in bytes: 244
Body size in bytes: 38
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""): text
Response code: 400
Response message: Bad Request
Response headers:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Wed, 11 May 2016 17:50:19 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 38
Connection: keep-alive
X-Request-Id: 88339ee9-b74f-4e22-b581-e3124949d067
X-Runtime: 0.030877
HTTPSampleResult fields:
ContentType: application/json; charset=utf-8
DataEncoding: utf-8
And the request looks like
/url redacted
POST data:
{"devices":{"uid":"jmtest","name":"newdevice"}
[no cookies]
Request Headers:
Connection: keep-alive
Accept: application/vnd.moneydesktop.v2+json
Content_Type: application/json
MD-SESSION-TOKEN: redacted
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Host: redacted
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_72)
The response data is
{
: "status":"400",
: "error":"Bad Request"
}
To send a POST HTTP Request with the JSON Data inside the body, need to add,
HTTP Header Manger into your request and set the name as 'content-type' and value as 'application/json' this will attached into HTTP request header and what ever the data inside your request body will send as json format.
Image 1:Set HTTP Header Manager,
Image 2:Set HTTP Request Body Data
Make sure your HTTP Header Manager is configured to send Content-Type header with the value of application/json
Given you have samplers like "home page" and "login" it might be the case you're missing HTTP Cookie Manager
The most straightforward way to see what's wrong is to capture requests sent by Postman (whatever it is) and JMeter by a sniffer tool like Wireshark, identify the differences and configure JMeter accordingly.
Finally, it looks like you're using some developer snapshot so approach to pass JSON payload as 1st argument without name might not work. Try switching to "Body Data" instead.
If above steps won't help update your question with screenshots of View Results Tree listener (all 3 tabs) and Postman
Check out Testing SOAP/REST Web Services Using JMeter for more tips.
This solution from Dmitri T, really worked for me.
Make sure your HTTP Header Manager is configured to send "Content-Type" header with the value of "application/json".
I have faced the same issue and it was resolved by setting the value of Content Encoding to utf-8 in http request. Please try.
First thing you might wanna do is put the payload inside "Body Data" Instead of "Parameters"
Then, add a config element "HTTP Header Manager"
And add a parameter "content-type" With corresponding value "application/json"
Now hit. Should do!
I figured out my problem. I had set Content_type instead of Content-Type so it was creating two content type headers.
Though Hasiya explain really well but missed how to find http request.
If you chose http default will not see method option .
I had given HTTP/1.1 415 Unsupported Media Type
After deleting space before of HTTP Header Manager ,It got 200 and worked like a charm
You must use body data, not parameters. cut and paste it the next tab on your request. Also you should change implementation to Java and check if your token is valid. Finally check your results from view results tree reporting item. It must be work for you.
In addition to many said above, make sure that the copy/paste of Accept, Content-Type from website doesn't have a trailing space! It costs me many hours to figure it out. Just a caution.
Just edit to add that if that mistake happens, return code is 415: Unsupported Media Type
Insert your json in body data field.
In your HTTP Header Manager set the headers stores to:
"name" : Content-Type
"value": application/json
Yes, we need to pass the Content-Type header.
I faced the same issue and it took nearly a day to figure out until I came across this link - https://www.blazemeter.com/blog/performance-test-web-services
Header:
Name: Content-Type Value: application/json;charset=utf-8
If none of the abovementioned solutions work for you (as it was for me) take a second look at the HTTP Header Manager. I had empty header line there
Removing it solved the problem
I was facing the similar issue, the size of my request body was also huge so along with updating content-type as application/json, i gave content encoding as utf-8 and it worked perfectly fine.
As per your attached pic , You have pasted the request in queryparameters , the payload must be in body part
check the screenshot you have payload in queryParam section
Setting the HTTP header manager fixed the issue for me
HTTP Header Manager:
Name: Content-type and Value: application/json has resolved issue.
I have a simple RESTLET Service which returns a JSON representation, as shown below:
#Override
#Post("json")
public Representation helloWorld() {
Representation representation = new JacksonRepresentation<Hello>(new Hello("Hello World"));
representation.setMediaType(MediaType.APPLICATION_JSON);
representation.
return representation;
}
When I query this using cURL I get the response as expected:
{"greeting":"Hello World"}
However I do not get a response when I use the browser or POSTMAN or indeed any other web REST client. I get the response 'Could not get any response' from POSTMAN.
The preview of the POSTMAN request is:
POST /testingrestlet/hello HTTP/1.1
Host: 127.0.0.1:6000
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 5141cd87-505c-e813-0045-3b7f4aa54144
I would at least have expected a REST client such as POSTMAN to work, or am I missing something?
Any help appreciated.
Regards
I think that you should use an header Accept for the content negotiation (conneg). Your request should be:
POST /testingrestlet/hello HTTP/1.1
Host: 127.0.0.1:6000
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache
Postman-Token: 5141cd87-505c-e813-0045-3b7f4aa54144
As a matter of fact, since you specify the extension "json" in the annotation, Restlet expects that this header was sent with one of possible media types for JSON content. This hint is used to select the method for processing... You shouldn't have this problem if you remove the extension, as described below:
#Post
public Representation helloWorld() {
Representation representation
= new JacksonRepresentation<Hello>(new Hello("Hello World"));
representation.setMediaType(MediaType.APPLICATION_JSON);
(...)
return representation;
}
Hope it helps you,
Thierry
With help from Thierry's comments the issue was traced down to Google Chrome blocking requests to port 6000 as it considers them unsafe. The error was only visible in Chrome Debug mode where the ERR_UNSAFE_PORT error was reported. Changing to a higher port resolved the issue! Detail of this error can also be found here: https://superuser.com/questions/188006/how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports
I'm using Spring Data Rest for reading the records from amazon dynamodb. The service works fine except for output format.
The output I see from the service is -
---> HTTP GET
---> END HTTP (no body)
<--- HTTP 200 (1082ms)
: HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/hal+json
X-Application-Context: application
Server: Jetty(8.1.14.v20131031)
{"_links":{"search":{"href":"something"}},"_embedded":{"userInfoes":[{"id":"bde0ef42-30c2-4ccd-8b0f-44d718827f69","username":"dsds","password":"1234","highestscore":99,"_links":{"self":{"href":"something"}}}]}}
<--- END HTTP (291-byte body)
But I need it in the below format[where no extra "_embedded" and "_links" tags are present] to retrieve the values easily. I'm using retrofit in the service layer. Please help!
[{"id":"bde0ef42-30c2-4ccd-8b0f-44d718827f69","username":"dsds","password":"1234","highestscore":99,}]