Hi, I got problem with my http request
If I use like this every thing look ok .
here code:
let parameters: Parameters = ["log_old":"xxx", "log_new":"xxx"]
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default)
but, when I need to send some thing in header
here code:
let headers: HTTPHeaders = [
"Content-Type": "application/x-www-form-urlencoded",
"log_token": xxx]
let parameters: Parameters = ["log_old":"xxx", "log_new":"xxx"]
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
My server can get headers value, But missing all of parameters like not send parameters out.
I re-check many time. I really send not nil parameters. I check by remove headers: headers in Alamofire.request my server can read parameters, and if I add headers my server can get only headers and missing parameters.
pls help. Thank you.
@coredore you can run test case on that and verify does actually alamofire is setting everything or not , following is a sample test case which i copied from Alamofire Test cases , you can take this as reference and create your own test case and let me know does your test case is passing or not
```swift
func testRequestClassMethodWithMethodURLParametersAndHeaders() {
// Given
let urlString = "https://httpbin.org/get"
let headers = ["Authorization": "123456"]
// When
let request = Alamofire.request(urlString, parameters: ["foo": "bar"], headers: headers)
// Then
XCTAssertNotNil(request.request)
XCTAssertEqual(request.request?.httpMethod, "GET")
XCTAssertNotEqual(request.request?.url?.absoluteString, urlString)
XCTAssertEqual(request.request?.url?.query, "foo=bar")
XCTAssertEqual(request.request?.value(forHTTPHeaderField: "Authorization"), "123456")
XCTAssertNil(request.response)
}
Sorry, we use our GitHub project for bug reports and feature requests. In the future, you should open questions like this on Stack Overflow and tag alamofire.
Cheers. 馃嵒
From our Contribution Guidelines
We don't use GitHub as a support forum. For any usage questions that are not specific to the project itself, please ask on Stack Overflow instead. By doing so, you'll be more likely to quickly solve your problem, and you'll allow anyone else with the same question to find the answer. This also allows maintainers to focus on improving the project for others.
you should use URLEncoding.queryString, not JSONEncoding.default
you should use
URLEncoding.queryString, notJSONEncoding.default
Thank you!!! It works! :-)
you should use
URLEncoding.queryString, notJSONEncoding.defaultThank you!!! It works! :-)
Nice~
Most helpful comment
you should use
URLEncoding.queryString, notJSONEncoding.default