亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在IOS上發送HTTP POST請求

在IOS上發送HTTP POST請求

有只小跳蛙 2019-07-06 15:14:50
在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:

此外,我認為您不需要來自NSUrlConnectionDownloadDelegate協議的方法,只需要來自NSURLConnectionDataDelegate的方法,除非您需要一些下載信息。


查看完整回答
反對 回復 2019-07-06
  • 3 回答
  • 0 關注
  • 2742 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號