Description
Moya version ->10.0.1
I am made a LoginAPI class with following method implementation.
public var method: Moya.Method {
return .post
}
The Login Service allows only POST HTTP method.
The issue is even after specifying Moya method as POST, the service response returns 405 status code in service call first time. If I retry the same call, status code 200 is returned.
Logs with 405 status code:
Request: https://myURL/login
Moya_Logger: [07/01/2018 21:08:54] Request Headers: ["Content-Type": "application/json"]
Moya_Logger: [07/01/2018 21:08:54] HTTP Request Method: POST
Moya_Logger: [07/01/2018 21:08:54] Request Body: {"password”:”password”,”email”:”abc@del.com"}
Moya_Logger: [07/01/2018 21:08:54] Response: <NSHTTPURLResponse: 0x608000038ac0> { URL: Request: https://myURL/login } { Status Code: 405, Headers {
Allow = (
POST
);
Date = (
"Sun, 07 Jan 2018 15:35:42 GMT"
);
"Transfer-Encoding" = (
Identity
);
} }
Logs with 200 Status code:
Request: https://myURL/login
Moya_Logger: [07/01/2018 21:12:35] Request Headers: ["Content-Type": "application/json"]
Moya_Logger: [07/01/2018 21:12:35] HTTP Request Method: POST
Moya_Logger: [07/01/2018 21:12:35] Request Body: {"password”:”password”,”email”:”abc@del.com"}
Moya_Logger: [07/01/2018 21:12:38] Response: <NSHTTPURLResponse: 0x60400043ab80> { URL: Request: https://myURL/login } { Status Code: 200, Headers {
"Content-Type" = (
"application/json;charset=UTF-8"
);
Date = (
"Sun, 07 Jan 2018 15:39:26 GMT"
);
"Transfer-Encoding" = (
Identity
);
} }
Points to note:
- This url works perfectly in Postman everytime with 200 status code with POST method.
- On simulator, this is the behavior first time I run the app (fresh launch of the app). On next run or on retrying , it works.
- Tested the api call by refactoring it to an Alamofire call, it works.
Could someone please help with what could be the possible cause for this?
Activity
zhongwuzw commentedon Jan 7, 2018
Can you capture the packet when you request
Post
first time? Provide it can found the issue more specifically if you provideHTTP
content.LavareX commentedon Jan 8, 2018
@shwetachitlangia Please fill in the appropriate title, help others quickly understand your problem. :]
[-]5[/-][+]Status code 405 returned for the first POST call of the app eben when POST is an allowed method on the API.[/+][-]Status code 405 returned for the first POST call of the app eben when POST is an allowed method on the API.[/-][+]Status code 405 returned for the first POST call of the app even when POST is an allowed method on the API.[/+]shwetachitlangia commentedon Jan 8, 2018
@zhongwuzw Sorry, I am unable to track packets using Wireshark. But i rewrote the same api call with Alamofire and tested with same conditions, it works.
The issue seems to be with the First POST operation of the app.
The first GET operations works just fine.
AndrewSB commentedon Jan 8, 2018
@shwetachitlangia without more information it's going to be hard to help you debug your issue. This would be a massive bug in Moya if it is an issue with Moya, but (from the fact that hundreds, if not thousands of apps are in production with Moya) it's more likely an issue with your code than the library.
Do you think you can make a Playground/example project that shows the issue? Without wireshark logs that would be most helpful for us to get your bug sorted out.
shwetachitlangia commentedon Jan 8, 2018
Can this code help?
Doesn't seem like a code issue as we are calling the same API again and it works.
Cannot share an example project as we have secured services.
LavareX commentedon Jan 9, 2018
@shwetachitlangia The above code snippet provides insufficient information. Or you can request third-party public services (for example: https://httpbin.org), see the test will appear the same problem? In order to troubleshoot the problem.
karbhasin-zz commentedon Jan 15, 2018
@yangcaimu Facing exactly the same issue. Sending the following POST request -
Request: http://XXXXXX/YYYY/UUUIIUIIUIUIUIUIU
Moya_Logger: [15/01/2018 16:10:08] Request Headers: ["Content-Type": "application/json", "correlationId": "876578658769389283kjhgf"]
Moya_Logger: [15/01/2018 16:10:08] HTTP Request Method: POST
Moya_Logger: [15/01/2018 16:10:08] Request Body: {"password":"password","email":"shshs@sd.com"}..
Checked with server team, as per their logs, they are getting method type as "ST" instead of POST.
AS per Server Logs -
"o.s.web.servlet.DispatcherServlet - DispatcherServlet with name ‘dispatcherServlet’ processing ST request for [/YYYY/UUUIIUIIUIUIUIUIU]"
zhongwuzw commentedon Jan 16, 2018
@karbhasin , strange behavior, maybe the only solution is to get requests raw packet from client-side and server-side, then compare them to find the issue.
aloco commentedon Jan 17, 2018
Hi,
I am updating a project from Moya 7.0.0 (swift 2.x) to Moya 10.0.0, facing the same issue. @shwetachitlangia did you find any workarounds?
sunshinejr commentedon Jan 17, 2018
This is really strange and unfortunately all of you guys can't share your project to help us investigate it, right?
In that case, will any of you guys (@aloco, @karbhasin, @shwetachitlangia) want to make a quick call with me and we could try debug it on the fly? Being able to reproduce it and access to the server logs would be awesome.
shwetachitlangia commentedon Jan 17, 2018
@sunshinejr I can have a call with you. I can reproduce it. But don't have access to server logs.
My skype id is chitstcs.
SD10 commentedon Jan 17, 2018
@shwetachitlangia Did this issue occur after a migration to 10.0.1? If so, what was the previous Moya version where this issue was not present?
Sent with GitHawk
30 remaining items