发布 HTTP 数据错误
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是警报它无法显示 stringReplys,因为它是数据必须使用此转换为字符串:S
The problem was the ALERT it couldnt show stringReplys as it is a Data have to convert to string using this :S
似乎错误的一件事是您有:
并且我相信您想要使用:
我不确定
Content-Type
是否由其他调用自动设置,但这可能会导致问题数据未正确解码。One thing that seems wrong is that you have:
and I believe you want to use:
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.