在IOS上发送HTTP POST请求我正在尝试用我正在开发的iOS应用程序发送HTTPPost,但是推送永远不会到达服务器,尽管我确实获得了响应代码200(来自urlConnection)。我从来没有得到服务器的响应,服务器也没有检测到我的帖子(服务器确实检测到来自Android的帖子)我确实使用ARC,但已经将PD和urlConnection设置为强连接。这是我发送请求的代码 NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",dk.baseURL,@"daantest"]]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml"
forHTTPHeaderField:@"Content-type"];
NSString *sendString = @"<data><item>Item 1</item><item>Item 2</item></data>";
[request setValue:[NSString stringWithFormat:@"%d", [sendString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[sendString dataUsingEncoding:NSUTF8StringEncoding]];
PushDelegate *pushd = [[PushDelegate alloc] init];
pd = pushd;
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:pd];
[urlConnection start];这是我的委托代码#import "PushDelegate.h"@implementation PushDelegate@synthesize data;-(id) init{
if(self = [super init])
{
data = [[NSMutableData alloc]init];
[data setLength:0];
}
return self;}- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:
(long long)totalBytesWritten{
NSLog(@"didwriteData push");}- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long)
totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes{
NSLog(@"connectionDidResumeDownloading push");}- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destination
URL:(NSURL *)destinationURL{
NSLog(@"didfinish push @push %@",data);}- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWri
tten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
3 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
connectionDidFinishDownloading:destinationURL:
- 3 回答
- 0 关注
- 2708 浏览
添加回答
举报
0/150
提交
取消