2009-04-17 12 views

答えて

-2

はPOST呼び出しをdoestいくつかの基本的なコードですNSURLConnectionのデリゲートメソッド。

0

第二の答えは、おそらく必要なもののように見える:あなたが適切に実装する必要が

//url is the appropriate url for the http POST call 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
      [theRequest setHTTPMethod:@"POST"]; 

      NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; 
      if(theConnection) 
      { 
       webData = [[NSMutableData data]retain]; 
      } 
      else 
      { 
       NSLog(@"theConnection is NULL"); 
      } 

:ここ

0

//あなたはsendSynchronousRequest使用して同期NSURLConnectionを駆動することができます:returningResponse:エラー:正しいに(サーバーに送信され //が、応答が

を受信するまでそれが全体のスレッドをブロックします// thebodyData =ペイロードをフォーマット) //ペイロードのtheMimeType = mineType // urlはhttp POSTコールの適切なURLです

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
     [theRequest setHTTPMethod:@"POST"]; 

     NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; 
     if(theConnection) 
     { 
      webData = [[NSMutableData data]retain]; 
      // give the details of the payload -- mine time and body content. 
      [theRequest setValue: theMimeType forHTTPHeaderField:@"Content-Type"]; 
      [theRequest setHTTPBody:theBodyData]; 

     } 
     else 
     { 
      NSLog(@"theConnection is NULL"); 
     } 

// the delegate methods templates... 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [webData setLength:0]; // clear the data incase it was a redirect in between. 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [webData appendData:data]; // collect the data from server as it comes in. 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    [[NSAlert alertWithError:error] runModal]; // report the error 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    // Once this method is invoked, "webData" contains the complete result 
} 
関連する問題