IOS中用ASIFormDataRequest POST出錯

helloapple 发布于 2014/02/15 13:17
阅读 1K+
收藏 0
iOS

我的服務器端(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>

加载中
0
dake
dake
iOS端是移动2G的网络?
helloapple
helloapple
不是,是wifi,請問和這個相關麼?
0
hhhaya
hhhaya
要转成UTF-8
0
骥宇科技
骥宇科技
是post value里包含特殊字符的原因吧。
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部