New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Status code 405 returned for the first POST call of the app even when POST is an allowed method on the API. #1533
Comments
Can you capture the packet when you request |
@shwetachitlangia Please fill in the appropriate title, help others quickly understand your problem. :] |
@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. |
@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. |
Can this code help? //-------------------------------------------------------------------------
// Login APIs - Login user
//-------------------------------------------------------------------------
import Moya
let loginProvider = NetworkUtility.getMoyaProvider(LoginAPI.self)
public enum LoginAPI {
case loginUser([String: Any])
case forgotPasswordOTP(String)
case resetPassword([String: Any])
}
extension LoginAPI: TargetType {
public var baseURL: URL { return URL(string: ConfigData.shared.getURL(forKey: DefaultsKeys.baseURL))! }
public var path: String {
switch self {
case .loginUser:
return ConfigData.shared.getURL(forKey: DefaultsKeys.login)
case .resetPassword:
return ConfigData.shared.getURL(forKey: DefaultsKeys.resetPassword)
case .forgotPasswordOTP:
return ConfigData.shared.getURL(forKey: DefaultsKeys.forgotPasswordOTP)
}
}
public var method: Moya.Method {
switch self {
case .loginUser:
return .post
case .resetPassword, .forgotPasswordOTP:
return .put
}
}
public var task: Task {
switch self {
case .loginUser(let bodyParameters),
//UserLogin dictionaryRepresentation is used for this
.resetPassword(let bodyParameters):
return .requestCompositeParameters(bodyParameters: bodyParameters,
bodyEncoding: JSONEncoding.default,
urlParameters: [:])
case .forgotPasswordOTP(let email):
return .requestCompositeParameters(bodyParameters: [User.Keys.email: email],
bodyEncoding: JSONEncoding.default,
urlParameters: [:])
}
}
public var headers: [String: String]? {
return NetworkUtility.getHeaders()
}
public var sampleData: Data {
var data: Data! = nil
switch self {
case .loginUser:
data = NetworkUtility.loadJSON(jsonName: "3.33.4Success")
case .resetPassword:
data = NetworkUtility.loadJSON(jsonName: "ResetPassword")
case .forgotPasswordOTP:
data = NetworkUtility.loadJSON(jsonName: "VerifyUser")
}
return data
}
} |
@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. |
@yangcaimu Facing exactly the same issue. Sending the following POST request - Request: http://XXXXXX/YYYY/UUUIIUIIUIUIUIUIU Checked with server team, as per their logs, they are getting method type as "ST" instead of POST. AS per Server Logs - |
@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. |
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? |
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. |
@sunshinejr I can have a call with you. I can reproduce it. But don't have access to server logs. |
@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 |
@SD10 we have started facing this issue from 10.0.0 |
Hi, trying to investigate the issue but it seems very strange to me. First it doesn´t happen with every
The request setup looks correct since MoyaLogger prints the request correctly. I think this happens also only with long url´s @shwetachitlangia can you confirm this? |
Can you guys check with a proxy (like |
@shwetachitlangia did this issue not show up on an earlier version? 9.x, for example? |
@AndrewSB Yes, did not face it with 9.x. |
@aloco So, the issue is "POST" becomes "ST" and "DELETE" becomes "LETE". |
@shwetachitlangia I think only two reasons, one is |
Hi All,
So compare to both in 8.0.3 version `case requestPlain
Now the final result is
` public var parameters: [String: Any]? {
}` Hope it will be helpful Thanks.. |
It looks like we have 4 people experiencing this issue and they mention it wasn’t present in Moya 8.0. We refactored the Can anyone who is experiencing the issue put together an example project that replicates it? Tagging @Dschee in case he can give any insight Sent with GitHawk |
I've read through the thread, but I can't remember anything that might cause this error related with the refactoring of Task. Also the code was refactored quite a bit after me implementing the initial feature. What I'd suggest the people seeings this issue to do:
This way we can isolate the time frame the issue was introduced more exactly. |
I tried |
@Dschee Thanks...
` public var task: Task {
@SD10 May I know the above logic is perfect or anything wrong.Now I am getting my results perfectly, However I need to check my entire project... |
These are the server logs - |
'ST' means...? it should be 'POST' right? |
How many people are using Spring here? |
@SD10 Yes, the Services team is using Spring Boot. |
This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I suspect this issue is unrelated to Moya and is in fact a problem with Spring. Going to ask Mr. Stalebot to keep this open Sent with GitHawk |
This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 🙏 Also, feel free to open a new issue if you still experience this problem 👍. |
I also encountered the same problem. After deleting the unused case in enum, the problem is solved. I don't know why. |
I had this problem on react-native app (ios) |
Moya version ->10.0.1
I am made a LoginAPI class with following method implementation.
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:
Could someone please help with what could be the possible cause for this?
The text was updated successfully, but these errors were encountered: