我的服務器端(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>
[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>
解决方案 »
- 想问一下,腾讯开放平台申请的应用里面的key不是即时生效的吗?
- java.io.IOException: getSecretKey failed: PBE SecretKeyFactory not available
- 请问如何在另一个程序中引用一个没有Nib, xib的项目?谢谢!
- IMac、IPhone问题请教
- 点击tableview中的textField为什么没有出发 didSelectRowAtIndexPath事件?
- 在网上看到这句代码,不知道什么意思
- 有人遇见过iOS6系统在关闭APP后MCU下位机没有收到关闭APP的命令
- curl curl_easy_setopt 执行崩溃,请指教。。。
- ios设备上面显示电池和信号的那条矩形叫什么
- 微信分享连接点击后出现正在加载,无法跳转到iTunes 的app下载页面?
- 怎样通过java调用IOS系统图片选择器?
- 用OC语言,编译一款推箱子游戏。
[request1 addPostValue:@"\{\"abc\"\}" forKey:@"str"];
不知道这样行不行
看下这篇文章:
http://blog.csdn.net/yuanbohx/article/details/10343179