0

UITextField を介してアプリケーションから値を送信する必要があり、リクエストを送信した Web サイトにこの値を表示したいと考えています。ASIHTTPRequest を使用して Web サイトにリクエストを送信します。私はこのようなことを試しました:

    NSURL *url = [NSURL URLWithString:@"http://www.project4hire.com/freelance_job_16265.html"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
//
[request setPostValue:priceField  forKey:@"bid"];
[request setPostValue:dayField forKey:@"days2c"];
[request setPostValue:commentField forKey:@"comment"];
[request setPostValue:@"1" forKey:@"notify"];
[request setPostValue:@"placebid" forKey:@"Place Bid >>"];
[request setPostValue:@"e6fb12104854e6e9" forKey:@"suid"];
[request setPostValue:@"placebid" forKey:@"a"];
[request setPostValue:@"16265" forKey:@"pid"];

[request setDelegate:self];
[request setDidFailSelector:@selector(requestBidFailed:)];
[request setDidFinishSelector:@selector(requestBidFinished:)];
[request startAsynchronous];

}
- (void)requestBidFailed:(ASIHTTPRequest *)request
{
//notify user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending         request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

}

- (void)requestBidFinished:(ASIHTTPRequest *)request
{
NSLog(@"Status: %d", request.responseStatusCode);
NSLog(@"string: %@",request.responseString);
}

入札フォームは次のとおりです: BidForm リクエストおよび応答ヘッダーは次のとおりです: Header

応答 200 を受け取りましたが、送信した値が Web サイトに表示されません。誰でも私にアドバイスできますか?

ありがとう

4

2 に答える 2

0

私は同じ問題を抱えていましたが、私はシミュレーターで作業していましたが、デバイスでは機能していませんでした。その後、ASIHTTPRequest API の創設者がライブラリを更新しなくなったことを示す記事を読みました (その記事が信頼できるかどうかはわかりません)。 、そのため、RestKit である更新されたライブラリを使用することにしました。次の Web サイトからダウンロードしてセットアップできます: restkit.org。インストールに問題がある場合は、私に連絡してください。レストキット ライブラリに投稿するための簡単なコードを次に示します。

- (void)post
{
    [RKClient clientWithBaseURLString:@"http://www.project4hire.com"];

    NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                            priceField, @"bid",
                            dayField, @"days2c", nil];

    [[RKClient sharedClient] post:@"/freelance_job_16265.html" params:params delegate:self];
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
    NSRange range = [[error localizedDescription] rangeOfString:@"-1012"];
    if (range.length > 0){
        //Do whatever here to handle authentication failures
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending         request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    RKLogError(@"Hit error: %@", error);
}

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response
{
    if ([request isGET]) {
        // Handling GET /foo.xml

        if ([response isOK]) {
            // Success! Let's take a look at the data
            NSLog(@"Retrieved XML: %@", [response bodyAsString]);
        }

    } else if ([request isPOST]) {

        // Handling POST /other.json
        if ([response isJSON]) {
            NSLog(@"Got a JSON response back from our POST!");
        }

    } else if ([request isDELETE]) {

        // Handling DELETE /missing_resource.txt
        if ([response isNotFound]) {
            NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
        }
    }

    NSLog(@"HTTP status code:     %d", response.statusCode);
    NSLog(@"HTTP status message:  %@", [response localizedStatusCodeString]);
    NSLog(@"Header fields: %@", response.allHeaderFields);
    NSLog(@"Body: %@", response.bodyAsString);
}
于 2012-09-10T04:12:41.330 に答える
0

HTML ファイルに投稿していることに気付きました。HTML ファイルを実行可能にするための特別な設定がない限り、html ファイルは投稿されたデータを処理しません。1 つの値だけが表示されていないのか、それともすべての値が表示されていないのか。すべての値が欠落している場合、最初に述べたことは正しいので、PHP、CF、Perl、またはアプリから投稿するデータを受け取りたい言語などを使用する必要があります。

于 2012-09-10T03:49:28.470 に答える