发布 HTTP 数据错误

发布于 2024-09-14 01:40:56 字数 1136 浏览 6 评论 0原文

    NSString *myRequestString = [NSString stringWithFormat:@"&nbr=%@&import=%@",tmpString,noSpaces];

NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: @"http://mysite.com/contacts.php" ] ]; 
[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: myRequestData ];
[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];    
NSData *stringReplys = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];


contactprogress.progress = 1;   
StatusLabel.text = @"Status: Complete";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:stringReplys
                                               delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];   
[alert release];

tmpStrings 只是一个电话号码,例如= 07919327368,noSpaces 是一个联系人和号码列表,格式不带空格,我不明白为什么这不起作用?

我知道 php 没问题,因为我可以通过我的电脑发送帖子,

谢谢梅森

可能是数据太大了

    NSString *myRequestString = [NSString stringWithFormat:@"&nbr=%@&import=%@",tmpString,noSpaces];

NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: @"http://mysite.com/contacts.php" ] ]; 
[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: myRequestData ];
[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];    
NSData *stringReplys = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];


contactprogress.progress = 1;   
StatusLabel.text = @"Status: Complete";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:stringReplys
                                               delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];   
[alert release];

tmpStrings is just a number phone number like = 07919327368 and noSpaces is a list of contacts and numbers formatted with no spaces i cannot see why this would not work ?

I know the php is fine as i can send post's via my pc

Thank you

Mason

Could it be that the data is too large

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸢与 2024-09-21 01:40:56

问题是警报它无法显示 stringReplys,因为它是数据必须使用此转换为字符串:S

stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];

The problem was the ALERT it couldnt show stringReplys as it is a Data have to convert to string using this :S

stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
原谅我要高飞 2024-09-21 01:40:56

似乎错误的一件事是您有:

[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];    

并且我相信您想要使用:

[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];    

我不确定 Content-Type 是否由其他调用自动设置,但这可能会导致问题数据未正确解码。

One thing that seems wrong is that you have:

[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];    

and I believe you want to use:

[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];    

I'm not sure if the Content-Type is getting set automatically by some other call, but that could cause a problem with the data not being decoded correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文