NSURLConnection-GET-ANFRAGE

Stieß ich auf NSURLConnection, habe ich es vor, einfach auf Anfrage, und das abrufen von Daten und analysieren Sie. Doch diese Zeit web-developer entwickelt hat GET-und POST-Anfragen.

Möchte ich durch viele tutorials und stack-Frage und versuchte gewünschte Ergebnis.
Wie ich sehe, gibt es irgendwann verlangen, wie dies

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"URL"]
                                                       cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                   timeoutInterval:10];

[request setHTTPMethod: @"GET"];

NSError *requestError;
NSURLResponse *urlResponse = nil;


NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];

auch einige andere, die ich gesehen habe.

Ich einfach aussieht, aber ich bin nicht in der Lage zu finden, was erforderlich ist, für alle POST und GET-Anforderung.

Den Daten, die ich empfangen habe von meinem web-Entwickler

SOAP 1.2


POST /DEMOService/DEMO.asmx HTTP/1.1
Host: projects.demosite.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

und im Gegenzug gibt es GET-und POST -

Folgenden ist eine Beispiel-HTTP-GET-Anfrage und-Antwort. Die Platzhalter angezeigt werden müssen, durch aktuelle Werte ersetzt werden.

     GET /DEMOService/DEMO.asmx/VerifyLogin?username=string&password=string&AuthenticationKey=string HTTP/1.1


    Host: projects.demosite.com

Ich bin sehr wohl der Delegierten der NSURLConnections, die folgenden..

#pragma mark NSURLConnection Delegate Methods

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//A response has been received, this is where we initialize the instance var you created
//so that we can append data to it in the didReceiveData method
//Furthermore, this method is called each time there is a redirect so reinitializing it
//also serves to clear it
_responseData = [[NSMutableData alloc] init];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
//Append the new data to the instance variable you declared
[_responseData appendData:data];
}

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
              willCacheResponse:(NSCachedURLResponse*)cachedResponse {
//Return nil to indicate not necessary to store a cached response for this connection
return nil;
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//The request is complete and data has been received
//You can parse the stuff in your instance variable now

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//The request has failed for some reason!
//Check the error var
}

DAS EINZIGE, WO ICH GEBLIEBEN BIN IST

Wie Anfrage schreiben, wo ich Argumente, in GET-oder POST-Anfrage.

Dank

InformationsquelleAutor Duaan | 2013-09-15

Schreibe einen Kommentar