我还很新,并且面临发送api请求的问题

问题描述 投票:0回答:1
<<

struct request { func getMessage(message:String){ let parameters: [String:Any] = [ "message" : [ "text": message, "type":"text" ], "type":"message", "recipentId":"", "info": [ "token":"" ] ] makeRequest(parameters: parameters) } func makeRequest(parameters:[String:Any]){ AF.request("https://bot.ortus4c.com/api/botController/token/5cc1f42e66d0ba0001dbf944",method: .get,parameters: parameters).response{ response in debugPrint(response) } }

执行此代码后,我得到:

[Request]: GET https://bot.ortus4c.com/api/botController/token/5cc1f42e66d0ba0001dbf944?info%5Btoken%5D=&message%5Btype%5D=text&message%5Btext%5D=&recipentId=&type=message [Request Body]: None [Response]: [Status Code]: 415 [Headers]: Accept: application/json Content-Length: 0 Date: Sat, 07 Mar 2020 18:51:08 GMT Server: cloudflare cf-cache-status: DYNAMIC cf-ray: 570681904ca52936-OTP expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" x-b3-traceid: 54bc25e66235804f [Response Body]: None [Data]: None [Network Duration]: 0.3918650150299072s [Serialization Duration]: 0.0s [Result]: success(nil)

我知道我一直在发送参数而不是正文,所以我如何发送看起来像这样的正文:

let parameters: [String:Any] = [ "message" : [ "text": message, "type":"text" ], "type":"message", "recipentId":"", "info": [ "token":"" ] ]

我对新手来说是个新手,我面临着alamofire的问题,我想做的是发送带有json正文的get请求,但我在这里遇到了我的代码:struct request {func getMessage(...
swift api post
1个回答
0
投票
您应该将方法更改为post
© www.soinside.com 2019 - 2024. All rights reserved.