Received invalid pass data (A newer version of iOS is needed to read this pass) - ruby

I have implemented all 5 endpoints in Ruby On Rails and all seems working fine. But when I provide updated pass in response to web service Getting the Latest Version of a Pass(GET request to webServiceURL/version/passes/passTypeIdentifier/serialNumber) the pass is not updated and in error log I am receiving following error.
"log"=>{"logs"=>["[2023-02-20 13:19:41 +0530] Get pass task (pass type pass.com.staging, serial number basic_5628, if-modified-since (null); with web service url https://0407-152-57-190-212.in.ngrok.io/api) encountered error: Received invalid pass data (A newer version of iOS is needed to read this pass.)"]}
Also I am not sure what to pass in response to Getting the Latest Version of a Pass web service. Whether I should pass updated pass.json or raw file of pass.pkpass or downloadable format of pass.pkpass, because in Apple PassKit Web Service Reference guide its written like If request is authorized, returns HTTP status 200 with a payload of the pass data. So I am not sure what to pass as payload.
All my endpoints and entire code are in Ruby On Rails.
Sample Code:
send_data #pass.data.stream.string, type: 'application/vnd.apple.pkpass', disposition: 'attachment', filename: "pass.pkpass"
API Response Details:
Response Format Binary
Response Object pkpass

Related

Spring RestTemplate Response string is shorter than expected

I am trying to get an access token via RestTemplate.postForEntity().
myRestTemplate.postForEntity(authBaseUrl, request, Object.class);
I have a specific class for it, but let's use now a simple Object as type. It contains an access_token field.
It works, because I can get response, but the length if the access tokens (which is a string)
is 1196 character long. And I can get the same length in Postman too.
But if I use the intelliJ built-in REST client, the length is 1199.
Only the token from the intelliJ rest client works (So the longer).
Because I always get a new access token, it is impossible to get the same token twice.
How can I debug it?
What could be the problem?
Is the code that generates the response available to you? if so in your response add a header content-length so you can see what the server sent and what you received. Also, debug the server side and see what is being generated. In addition take another 3d party Http client and test it with this client see if you see a difference. The Http clients that you can try are Apache Http client, OK Http client, or my favorite - a very simplistic client written by me as part of my own Open Source MgntUtils library. Here is the Javadoc for my http client Here is a link to a similar question where you can get the references for any of above mentioned Http clients: How to check the status of POST endpoint/url in java

JMeter - Getting 400 Bad Request

In JMeter - I am getting 400 bad request.
I have validated the JSON format, JSON request is correct. But showing error in Request body as
Error: "Cannot assign " ": "Address.created_by" must be a "User" instance."
In Header manager- I have included all the correct Content-Type and other headers as well.
Could you please provide a solution for this error?
This is due server side validation failing and server returning 400 - Bad Request. Please check the same request object in Postman or SoapUI
JSON request might be correct but JSON request body seems to be incorrect, cross check your request body with API specification documentation i.e. Swagger UI it might be the case that API contract has changed and your test is sending the request in the "old" format.
Also Taurus framework has a special tool for converting Swagger API definitions into Taurus YAML files which in their turn can be converted into JMeter .jmx scripts

AFNetworking says "cannot parse response"

I am sending a request to server, which is handling the request and responsding. However on my app I am receiving:
Error Domain=NSURLErrorDomain Code=-1017 "cannot parse response" UserInfo=0x167668d0
{NSErrorFailingURLStringKey=https://***, _kCFStreamErrorCodeKey=-1,
NSErrorFailingURLKey=https://***/, NSLocalizedDescription=cannot
parse response, _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x16731990 "cannot parse
response"
Accept field in http request is adequate.
I cannot even see what messege is arriving, because NSHTTPURLResponse object is null.
What can be an issue and in what way I can see what message is coming not using things like wireshark.
Thank You!
I got the same problem, and the reason is that the API require GET http method, and I need pass a parameter, I send it by the following code:
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
When I execute the request with GET method, it will report the error.
My solution is when the API need GET method, the parameter should add on the URL, such as http://apiserver/api?paramName=paramValue, when the API method is POST, then use the code above, set the HTTPBody for the request object.
If iOS cannot parse response, the problem must be in improper format http response from server, even if You are said, that everything is 100% correct, bacause other services communicate with it.
In my case an Android app communicated successfully, because network framework used there was not so restrictive and even if the content-length of http response does not fit the actual length of data, it could read this message, unlike ios.
Use tcpdump to check http communication!
I got the same issue when I tried to call a web method using http GET method instead of http POST. The web service method was expecting POST request not GET. Hope this information will help some one.
If you are using (iOS8 has a problem with this but works in iOS7)
NSData *dataToSend = [jsonData dataUsingEncoding:NSUTF16BigEndianStringEncoding]
to send to the server, please make it as per below:
NSData *dataToSend = [jsonData dataUsingEncoding:NSUTF8StringEncoding]
I was seeing this error because a framework I was using was trying to send URL parameters in a GET request inside a JSON encoded body (instead of as URL-encoded parameters in the URL string as it should have been). That was causing the server send back an "invalid parameters message" which the client couldn't handle and instead aborted mid-request. Switching from body parameters to URL-encoded parameters for GET requests fixed the problem.
First I would ensure you are sending the correct parameters both in the body and the headers. I was receiving this error and after moving one of the parameters from the body into the header I received the correct response.
If there is any documentation for the api make sure you follow it properly.

Getting 400 Bad request error when sending huge amont of data with post

I am using yahoo YUI Ajax call to post request.
Page is developed in JSP and server is Tomcat 6 and using Struts 2.x.
While i am sending small amount of data using Ajax call post request it is working fine.But when i am sending huge amount of data i am getting 400 bad request error.
The 400 error comes when The Web server thinks that the data stream sent by the client (e.g. your Web browser ) was 'malformed' i.e. did not respect the HTTP protocol completely. So the Web server was unable to understand the request and process it.
There could be possibilities that data is too large, so you should better encode the data using java script inbuilt function for example escape().
Please check maxPostSize attribute of Connector in conf/server.xml.
See the following doc for the details
In Tomcat, when the post data exceeds the maximum specified in maxPostSize (server.xml) it returns a 400 as error code

ASP.NET MVC 4 Web Api: POST with unknown or not specified Content-Type

My web api returns the error code 500, if a client POST's some data and not specifying the content-type.
The Error-Message
No MediaTypeFormatter is available to read an object of type
'Document' from content with media type ''undefined''.
show that the server can't find a formatter.
But in this case: "no content-typ or unknown content-type set by the client", the client is responsible for the error - not the server.
Instead of an error code 500, the web api should return somthing like 4XX.
My question is: How can I configure the web api that it will return a status code 400.
An other exapmle is: While content negotiation: If The client sends that he accept XML, but the server cant send XML but JSON, the server sends JSON anyway. In this case the web api should return the status code: 406 Not Acceptable.

Resources