Ios 如何在Objective-C中模拟这个curl语句?

Ios 如何在Objective-C中模拟这个curl语句?,ios,objective-c,post,curl,afnetworking,Ios,Objective C,Post,Curl,Afnetworking,我想发布一个API(使用JSON),我可以通过bash脚本通过curl很好地完成它,但是在Objective-C中完成同样的任务时我遇到了很多麻烦(我使用AFNetworking,但不必如此) 下面是curl命令(删除了我的API标记),它可以工作: curl -d 'token=...' -d 'batch=[{"method":"GET","relative_url":"/api/article?token=...%26url=http://www.macrumors.com/2014/01

我想发布一个API(使用JSON),我可以通过bash脚本通过
curl
很好地完成它,但是在Objective-C中完成同样的任务时我遇到了很多麻烦(我使用AFNetworking,但不必如此)

下面是curl命令(删除了我的API标记),它可以工作:

curl -d 'token=...' -d 'batch=[{"method":"GET","relative_url":"/api/article?token=...%26url=http://www.macrumors.com/2014/01/12/your-verse-ipad-ad/"}]' http://diffbot.com/api/batch
下面是我在Objective-C中使用AFNetworking的尝试(同样,删除了令牌):

当我使用并选择“JSON Text”监控HTTP流量时,它声称我正在向API发送以下内容:

{
    "token": "...",
    "batch": "[{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/www.macrumors.com\\\/2014\\\/01\\\/12\\\/your-verse-ipad-ad\\\/\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/gigaom.com\\\/2013\\\/08\\\/14\\\/honest-chromecast-review\\\/\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/www.theverge.com\\\/2013\\\/8\\\/14\\\/4622122\\\/oldest-board-game-tokens-found-turkey\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/mobile.slate.com\\\/articles\\\/business\\\/moneybox\\\/2013\\\/08\\\/microsoft_ceo_steve_ballmer_retires_a_firsthand_account_of_the_company_s.single.html?original_referrer=http%3A%2F%2Ft.co%2FyOO5N2OQxZ&utm_campaign=Buffer&utm_content=buffer47791&utm_medium=twitter&utm_source=buffer\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/gigaom.com\\\/2013\\\/08\\\/27\\\/whos-your-new-mobile-carrier-how-bout-wi-fi\\\/\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/www.bloomberg.com\\\/news\\\/2013-11-10\\\/apple-said-developing-curved-iphone-screens-enhanced-sensors.html\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/9to5mac.com\\\/2013\\\/10\\\/04\\\/itunes-radio-launch-in-canada-imminent-as-apple-seeks-programmers\\\/\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/gizmodo.com\\\/5926728\\\/sony-smartwatch-review-maybe-the-worst-thing-sony-has-ever-made\"},{\"method\":\"GET\",\"relative_url\":\"\\\/api\\\/article?token=...&fields=text,title,url&url=http:\\\/\\\/njnewscommons.org\\\/the-news-in-jersey-august-27-2013-obama-and-the-future-of-investigative-journalism\\\/\"}]"
}
这显然是错误的


与API交互到底有什么不对?

curl使用URL编码
application/x-www-form-urlencoded
对数据进行编码。您正在使用JSON

改变

[[AFDiffbotClient sharedClient] setParameterEncoding:AFJSONParameterEncoding];

[[AFDiffbotClient sharedClient] setParameterEncoding:AFJSONParameterEncoding];
[[AFDiffbotClient sharedClient] setParameterEncoding:AFFormURLParameterEncoding];