我们现在android手机客户端和服务端用json通信,程序运行正常.
但用iphone,用json写,代码如下
NSString *str = @"{\"UserName\":\"[email protected]\",\"Password\":\"qwerty\"}";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.phonepa.net:8384/user/login"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40];
[request setHTTPMethod: @"POST"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [str dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"str=%@", str);
NSLog(@"post data = %@", [request HTTPBody]);
NSURLResponse *response = nil;
NSError *error = nil;
NSData * data =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString* strRet = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"STRRET= %@", strRet);
[strRet release];
服务端返回错误信息:
>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.er {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head> <body bgcolor="white"> <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> <h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 <br><br> <b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br> <b>源错误:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code> </td>
</tr>
</table> <br> <b>堆栈跟踪:</b> <br><br>
梦回童年 22:24:17
html>
<head>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.er {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head> <body bgcolor="white"> <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> <h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 <br><br> <b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br> <b>源错误:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code> </td>
</tr>
</table> <br> <b>堆栈跟踪:</b> <br><br>
但用iphone,用json写,代码如下
NSString *str = @"{\"UserName\":\"[email protected]\",\"Password\":\"qwerty\"}";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.phonepa.net:8384/user/login"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40];
[request setHTTPMethod: @"POST"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [str dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"str=%@", str);
NSLog(@"post data = %@", [request HTTPBody]);
NSURLResponse *response = nil;
NSError *error = nil;
NSData * data =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString* strRet = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"STRRET= %@", strRet);
[strRet release];
服务端返回错误信息:
>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.er {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head> <body bgcolor="white"> <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> <h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 <br><br> <b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br> <b>源错误:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code> </td>
</tr>
</table> <br> <b>堆栈跟踪:</b> <br><br>
梦回童年 22:24:17
html>
<head>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.er {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head> <body bgcolor="white"> <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> <h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 <br><br> <b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br> <b>源错误:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code> </td>
</tr>
</table> <br> <b>堆栈跟踪:</b> <br><br>
解决方案 »
- xcode代码提示
- 怎么等待一个线程结束
- iPhone4S 开机密码忘记了,机子被锁定,求帮助!
- 关于NSGenericException-使用NSEnumerator
- 如何将untitled.plist中的信息放到tablevie中呢??
- 询问关于iPhone应用程序中播放YouTube视频的问题
- ios 提供某种协议,让其他程序来读取数据
- 求理解 UIApplicationmain函数调用语法
- 求助:用过Google Analytics或Flurry的并且了解C# Winform的进来瞅瞅吧!
- 如何判断两个View的background是否相等
- 求助-IPAD 充电时,右上角,为什么会显现“没有充电”
- 请问如何将自己的iphone应用发布到app store上?
那看看服务器怎么解析的,有没有问题。