rapher.de – 2 cent blogging

Compu-Global-Hyper-Mega-Net

Juni 14th, 2010

Codeschnipsel: Kommunikation vom iPhone zu Google App Engine via HTTP GET

iPhone Developing, by rapher.

Hier mal ein Codeschnipsel für das Senden von Informationen über einen HTTP GET Request vom iPhone zur Google App Engine (Java):

// iPhone send GET
NSString *urlString = [NSString stringWithFormat: @"http://appname.appspot.com/saveText?text1=%@&text2=%@", self.text1Label.text, self.text2LabelLabel.text];
NSURL *urlToSend = [[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlToSend cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

in urlData landet die Antwort vom Server, also z.B. ein return vom doGet (s.w.u.)


// Google App Engine get GET
import javax.servlet.http.*;
[...]
public class getHTTP_GET extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

String text1 = req.getParameter("text1");
String text2 =req.getParameter("text2");

// do something

return /sendBack
}

In der web.xml muss nun noch von /saveText auf das getHTTP_GET Servlet verwiesen werden.

Back Top

Responses to “Codeschnipsel: Kommunikation vom iPhone zu Google App Engine via HTTP GET”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*