我正在尝试将curl调用转换为ASIHTTPRequest,我基本上成功了,除了无法发送消息位。
curl:
curl -d "hello world"
"http://api.pusherapp.com/apps/11776/channels/test_channel/events?"
"name=my_event"
,这是它作为ASIHTTPRequest:
的样子NSString *url = @"http://api.pusherapp.com/apps/11776/channels/test_channel/events?name=my_event";
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request setRequestMethod:@"POST"];
[request startSynchronous];
它们都触发事件,但是curl调用将"hello world"作为消息发送,而ASIHTTPRequest则不会。
我试过将其添加为post变量或标题,但没有成功。关于如何将"-d消息"转换为其他格式的任何想法?
谢谢你,安德烈
您需要将您的消息添加到请求的正文中,例如通过使用这行代码:
[request appendPostData:[@"hello world" dataUsingEncoding:NSUTF8StringEncoding]];