在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 關注
- 2742 瀏覽
添加回答
舉報
0/150
提交
取消