Asiformdatarequest code example to implement post

Source: Internet
Author: User

The Post method implemented with jquery may be as follows

var param = $.param ({
Data:JSON.stringify ({"From": "234", "MessageID": "32132123", "to": "234", "Conversationid": "4123456", "timestamp" : 1459000790138, "type": 1, "Content": "ew", "ImageUrl": ""})
});
$http ({
Url:main_host_url + '/chat/createmessage ',
Method: "POST",
Data:param,
Headers: {' content-type ': ' application/x-www-form-urlencoded '}
}). Then (function (response) {
var data = Response.data,
Status = Response.Status,
Header = Response.header,
config = response.config;

Console.log (json.stringify (data));

if (status = = 200) {

}
$ionicLoading. Show ({template:data.m, nobackdrop:true, duration:2000});

Scope. $broadcast (' Scroll.refreshcomplete ');
}, function (response) {
Console.log ("Error:" + json.stringify (response));
var data = Response.data,
Status = Response.Status,
Header = Response.header,
config = response.config;

Json.stringify (
Scope. $broadcast (' Scroll.refreshcomplete ');
});

The same code, which can be converted to iOS, is implemented using Asiformdatarequest, with the following code:


. xx.h

@interface chatviewcontroller: uiviewcontroller<asihttprequestdelegate> {

}

Xx.m

-(void) postMessage {

nsstring *s = [nsstring stringwithformat:@ "Http://%@/chat/createmessage", Site_url];

asiformdatarequest *request = [[asiformdatarequest alloc] initwithurl: [Nsurl urlwithstring: s]];

nsstring *datas = @ "{\" from\ ": \" 234\ ", \" messageid\ ": \" 32132123\ ", \" to\ ": \" 234\ ", \" Conversationid\ " : \ "4123456\", \ "timestamp\": 1459000790138,\ "type\": 1,\ "content\": \ "ew\", \ "imageurl\": \ "\"} ";

{

nserror *error;

//[request addrequestheader:@ "Content-type" value:@ "application/x-www-form-urlencoded; Encoding=utf-8"];

//[request addrequestheader:@ "Accept" value:@ "Application/json"];

//[request setrequestmethod:@ "POST"];

//[request Setpostbody:tempjsondata];

[Request Setpostvalue:d atas forkey:@ "Data"];

[Request startasynchronous];

}

}

-(void) requestfinished: (asihttprequest *) Request

{

}

-(void) requestfailed: (asihttprequest *) Request

{

nserror *error = [request error];

}

Asiformdatarequest code example to implement post

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.