我的服務器端(WCF Rest):
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "data")]
string PostData(string str);public string PostData(string str)
{
   return str;
}IOS端:
NSURL *url = [NSURL URLWithString:@"http://192.168.1.188:8788/Service1/data"];
ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url];
[request1 addPostValue:@"{\"abc\"}" forKey:@"str"];
 [request1 setTimeOutSeconds:20];
[request1 setDidFailSelector:@selector(uploadFailed:)];
 [request1 setDidFinishSelector:@selector(uploadFinished:)];
[request1 setDelegate:self];
 [request1 startAsynchronous];//奇怪的是如果我把[request1 addPostValue:@"{\"abc\"}" forKey:@"str"]這一句注釋掉的話就能訪問到服務器(返回的是null,因為服務沒接收到POST的值str),但一加上addPostValue就會出現下面的錯誤了,在網上找了很久別人說是IOS調用時addPostVaule時POST的參數格式有問題,但我不知道要如何才是正確的格式,希望有經驗的大神們幫幫我,感激不盡。錯誤信息(返回的中文有亂碼):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>èæ±‚錯誤</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">èæ±‚錯誤</p>
      <p xmlns="">伺服器處理èæ±‚時發生錯誤。請參閱<a rel="help-page" href="http://192.168.1.188:8788/Service1/help">服務說明頁</a>,了è£å‚何建立åæœå‹™çš„有效èæ±‚。</p>
    </div>
  </body>
</html>