2012-04-12 2 views
0

ASIHTTPRequestのappendPostDataメソッドを使用して文字列データをPHPサーバーに送信したいが、機能しない。ASIHTTPRequest appendPostDataが機能しない

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
[request appendPostData:[@"123456" dataUsingEncoding:NSUTF8StringEncoding]]; 
[request startAsynchronous]; 

私は次のようにリクエスト自体にいくつかの変更を試してみました:

[request setRequestMethod:@"POST"]; 
[request buildPostBody]; 

だけでなく、これは動作しません。

私はそれが仕事をし

[request addPostValue:@"Ben" forKey:@"names"]; 

構文を使用します。

誰もが何を考えているのですか?

答えて

1

私は通常、これを使用する:

- (void)performPostRequestWithString:(NSString *)string stringDictionary:(NSDictionary *)stringDictionary dataDictionary:(NSDictionary *)dataDictionary delegate:(id)requestDelegate requestSelector:(SEL)requestSelector errorSelector:(SEL)errorSelector { 

    //localCopy = self; 

    self.delegate = requestDelegate; 
    self.callback = requestSelector; 
    self.errorCallback = errorSelector; 

    NSURL *url = [NSURL URLWithString:string]; 

    postRequest = [[ASIFormDataRequest alloc] initWithURL:url]; 
    [postRequest setDelegate:self]; 
    [postRequest setRequestMethod:@"POST"]; 

    if (stringDictionary) 
     for (NSString *key in [stringDictionary allKeys]) 
      [postRequest setPostValue:[stringDictionary objectForKey:key] forKey:key]; 

    if (dataDictionary) 
     for (NSString *key in [dataDictionary allKeys]) 
      [postRequest setData:[dataDictionary objectForKey:key] forKey:key]; 

    //NSLog(@"request url = %@", [postRequest.url absoluteString]); 
    [postRequest startAsynchronous]; 
} 

パラメータ:

  • (NSString *)string - あなたの要求を投稿するURL文字列を、。
  • (NSDictionary *)stringDictionary - すべてのテキスト情報(名前、IDなど)を含む辞書。
  • (NSDictionary *)dataDictionary - すべてのデータ情報(写真、ファイルなど)を含む辞書。
  • (id)requestDelegate - 以下のセレクタを実行する代理人。
  • (SEL)requestSelector - 正常に要求されている間に実行されるセレクタ。
  • (SEL)errorSelector - エラーが発生している間に実行されるセレクタ。

P.S.セレクタはASIHTTPRequest Delegate実装で使用されます

+0

ありがとうございます! – user944351

関連する問題