Original: http://www.cnblogs.com/yuancong/articles/4447559.html
Failure--Error = Error Domain=afnetworkingerrordomain code=-1011 "Request failed:not found (404)" userinfo=0x7fb471f181 Ten {nslocalizeddescription=request failed:not found (404), nserrorfailingurlkey=http://114.85.246.110:11111/ Iappservice/insertpurchaseremainpa, Afnetworkingoperationfailingurlresponseerrorkey=<nshttpurlresponse: 0x7fb471f7d300> {Url:http://114.85.246.110:11111/iappservice/insertpurchaseremainpa} {status code:404, headers {
"Content-length" = 1565;
"Content-type" = "text/html; Charset=utf-8 ";
Date = "Wed, Apr 06:53:07 GMT";
Server = "microsoft-httpapi/2.0";
}}, Nsunderlyingerror=0x7fb471f06ab0 "Request failed:unacceptable content-type:text/html"}
"No endpoints found" appears on the Web page, and then I have a lot of solutions on the Internet, such as
1. See if it's HTTP or JSON
Manager.responseserializer = [Afjsonresponseserializer serializer];
2.text/html that to take a look at the newspaper what is wrong, sometimes this sentence does not necessarily need.
3.params There is no problem, there is no mapping error.
Specifically see the requirements of the interface, with Get or post, what type of data, what to pass the reference. I just tried it out one by one.
The above is a big God on the Internet to say the solution, you can try, basically almost, but my problem is special, the TMD is the server over the problem, how to try not to work, so there is a problem when you do not have a person in that blind try, to let the server side best also try, It's best that he can test it. You are changing your own, make sure that everything he gives you is right or you will die.
The above 404 error is not access to the server, the server is ready, the interface address is confirmed that you can access the 404 error will not occur.
And then there's a new error, put the code first:
NSString *urlstr2 = @ "Http://114.85.246.110:11111/IAppService/InsertPurchaseRemainPay";
[Urlstr2 stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
nsdictionary *dic2 = @{@ "Shopid" :@ "802BB63B-7DBE-496D-BCB5-3F3F00848FFC" ,@ "Balance" :@10,@ "rebate" :@ 0,@ "Bankaccountid" :@ "08f2a9bb-f318-4be0-a4a5-33c0125ff137" @ "Banktradeno" :@ ",@" Orderpayid ":@" 00000000-0000-0000-0000-000000000000 ",@" paidsum ":@15 ,@ "Purchaseid" :@ "5a720bcf-c301-4a1d-ad37-24f04c8a6f5d" ,@ " State ":@0}
NSLog (@ "%@", Dic2);
Print out the data contents
nsstring *str2 = [dic3 jsonstring];
NSLog(@ "strrrr=====%@", str2);
Afhttprequestoperationmanager *manager1 = [Afhttprequestoperationmanager manager];
Manager1.requestserializer = [Afjsonrequestserializer Serializer];
Manager1.responseserializer = [Afhttpresponseserializer Serializer];
[Manager1 post:urlstr2 parameters:str2 success:^ (afhttprequestoperation *operation, ID Responseobject) {
NSLog (@ "Success-%@", operation. responsestring);
nsstring *str = [[nsstring alloc] initwithdata: Responseobject encoding: Nsutf8stringencoding];
NSLog(@ "success-str =%@", str);
} failure:^ (afhttprequestoperation *operation, nserror *error) {
NSLog (@ "Failure-%@", operation. responsestring);
NSLog(@ "Failure--error =%@", error);
}];
The above DIC is a server-given parameter model, that is, a dictionary, he said to convert to JSON to him, I am silly, do not know the dictionary is the TMD JSON data also hard to turn the dictionary into a JSON string to him, so the parameters are not old, he wants a dictionary model, So just pass him a dictionary, but add manager1.requestserializer = [Afjsonrequestserializer Serializer]; This sentence is configured , send the JSON request, the main idea is this, the specific self-Baidu.
Then, the interface address is confirmed, the parameters are also transmitted to, the return type is poor, afhttpresponseserializer this thing is to ask you to return the data yourself to parse, how to parse on how to parse, Afjsonresponseserializer, And this is the AF library for you to parse the returned JSON data, so block inside again write nsstring *str = [[nsstring alloc] initwithdata: Responseobject encoding: nsutf8stringencoding]; This sentence will collapse, because the parsed responseobject is an array, you directly return to the Responseobject on the line.
The final code is reduced to:
nsstring *urlstr2 = @ "Http://114.85.246.110:11111/IAppService/InsertPurchaseRemainPay";
nsdictionary *dic2 = @{@ "Shopid" :@ "802BB63B-7DBE-496D-BCB5-3F3F00848FFC" ,@ "Balance" :@10,@ "rebate" :@ 0,@ "Bankaccountid" :@ "08f2a9bb-f318-4be0-a4a5-33c0125ff137" @ "Banktradeno" :@ ",@" Orderpayid ":@" 00000000-0000-0000-0000-000000000000 ",@" paidsum ":@15 ,@ "Purchaseid" :@ "5a720bcf-c301-4a1d-ad37-24f04c8a6f5d" ,@ " State ":@0}
NSLog (@ "%@", Dic2);
Afhttprequestoperationmanager *manager1 = [Afhttprequestoperationmanager manager];
Manager1.requestserializer = [Afjsonrequestserializer Serializer];
Manager1.responseserializer = [Afjsonresponseserializer Serializer];
[Manager1 post:urlstr2 parameters:dic2 success:^ (afhttprequestoperation *operation, ID Responseobject) {
NSLog (@ "Success-%@", responseobject);
} failure:^ (afhttprequestoperation *operation, nserror *error) {
NSLog(@ "Failure--error =%@", error);
}];
Afnetworking POST request encountered problem resolution procedure