TheAkkaWay icon indicating copy to clipboard operation
TheAkkaWay copied to clipboard

Akka-http如何构造http POST request

Open PipsqueakH opened this issue 8 years ago • 3 comments

Akka-http的文档略显简略,貌似对很多细节问题都没有太多探讨和示例代码。

具体问题是 对如下请求如何构造HttpRequest?

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'field1=1field2=2' 'http://192.168.100.1/test'

尝试了

HttpRequest(method= HttpMethods.POST, uri = http://192.168.100.1/test, entity = FormData("field1"->1, "field2"->2).toEntity)

但不知道问题在哪里。 Content-Type 的header应该是不用设置的,还有哪里要改呢?

PipsqueakH avatar Apr 29 '17 15:04 PipsqueakH

@Hawstein PTAL

He-Pin avatar May 03 '17 03:05 He-Pin

@PipsqueakH 我觉得你需要加入更多的细节,我都没看懂你的问题是啥。。。报错了?不过你的header的确是没设置的。

He-Pin avatar May 03 '17 03:05 He-Pin

可以调用withHeaders

cjuexuan avatar May 03 '17 13:05 cjuexuan