首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >希伯来语作为服务器端的废话

希伯来语作为服务器端的废话
EN

Stack Overflow用户
提问于 2011-04-10 16:50:41
回答 1查看 890关注 0票数 0

我有一个iPhone模拟器应用程序作为客户端和WCF-REST,json编码的服务运行在IIS7.0服务器上。我尝试将一些希伯来语字符作为参数发送给服务,服务器返回错误代码400 - Bad Request。当我发送一个英文字符串时,服务器会按其应有的方式处理该字符串。

用于字符串编码的代码如下所示:

请注意," parameters“是即将发送到服务器的参数,排序为parameter_name => parameter_value。

代码语言:javascript
复制
//RPC JSON
NSString* reqString = [parameters JSONRepresentation];
//Request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]];
//prepare http body
[request setHTTPMethod: @"POST"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

我在服务器端得到的请求和响应(通过使用ethereal获得):

请求:

代码语言:javascript
复制
POST /SmsliMobileService.svc/SetContactGroups HTTP/1.1
Host: 192.168.10.22:8081
User-Agent: Beeper_3/1.0 CFNetwork/485.12.7 Darwin/10.7.0
Content-Length: 89
Accept: application/json
Content-Type: application/json; charset=UTF-8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

响应:

代码语言:javascript
复制
{"ApplicationID":"98534bb6-82ef-4937-83e7-10f65780bf36","contact_id":43,"groups":"עבו×HTTP/1.1 400 Bad Request
Content-Length: 1647
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sun, 10 Apr 2011 07:46:09 GMT

<?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>Request Error</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">Request Error</p>
      <p>The server encountered an error processing the request. See server logs for     more details.</p>
    </div>
  </body>
</html>

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-11 19:34:20

我在发布的代码中有一个错误。

代码语言:javascript
复制
NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]];

这一行(最初在问题的代码中)生成了错误-而不是获取从"reqString UTF8String“返回的字节数组的长度,给出了错误的长度-nsstring的长度...

固定代码:

代码语言:javascript
复制
const char *utf8String = [reqString UTF8String];    // no need to free me - autoreleased  object returned.
NSInteger l = strlen(utf8String);
NSData *requestData = [NSData dataWithBytes:utf8String length:l];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5610713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档