我正在尝试创建一个将数据发布到网址http://api.sourcelair.com/exec/create的应用,并且需要将数据与帖子一起发送。
这是需要发送到URL的数据
code : "The source code that you want to execute" ,
language : "The programming language of your code (e.g. C)"
input : "The optional standard input of your program"
我可以将数据发送到网址的代码是什么?
答案 0 :(得分:0)
如果您使用的是ASIHTTPRequest
这样的图书馆,那就像以下一样简单:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"The source code that you want to execute" forKey:@"code"];
[request setPostValue:@"The programming language of your code (e.g. C)" forKey:@"language"];
[request setPostValue:@"The optional standard input of your program" forKey:@"input"];
[request startAsynchronous];
当然,您需要设置委托和响应方法。您可以在此处ASIHTTPRequest
找到有关NSURLConnection
的更多信息,http://allseeing-i.com/ASIHTTPRequest/How-to-use
或者,您可以使用POST
类发出{{1}}个请求。更多信息请访问:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsurlconnection_Class/Reference/Reference.html