REST Web API POST调用给出错误

时间:2016-03-25 05:51:17

标签: ios objective-c rest asp.net-web-api

我想从我的iOS应用程序向网络服务发送POST请求。到目前为止,我已经发送了一个JSON对象,它正在工作。现在我想将数据作为参数发送。我做了类似的事。

my_list = [2, 1, 3]

# .sort() is a list method that applies the sorting logic to a
# specific instance of list, in this case, my_list
my_list.sort()

# sorted is a built-in function that's more generic which can be
# used on any iterable of Python, including list type
sorted(my_list)

这是我的[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[NSData dataWithBytes:[postParam UTF8String] length:[postParam length]]]; NSError *error = nil; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error: &error]; NSString *string = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 字符串

postParam

这是我的action=approve&requestId=0&reqDetailId=21&nextApproverCode=0&authIpAddress=122.127.0.114&remarks=Test&approval=C

request

但我收到了错误消息

<NSMutableURLRequest: 0x151323e60> { URL: http://<url>/Workflows/WorkflowApprovals? }

这是什么原因?
提前致谢

1 个答案:

答案 0 :(得分:0)

由于它是POST方法,您无法发送查询字符串

创建一个字典并传递其中的所有参数