[iPhone] How would one send data to an http server?

Hello,
I would like to be able to send data (maybe XML?) to be processed by a server-side script.
NSURLRequest seems to be mainly for downloading data, not uploading... A simple "ajax" request would do, so I would just serialize the data and send it in a POST variable. How do I implement such a request using the SDK?

This what iam doing to post XML and to receive an XML response from our servers. Note that the Content-Type is set to text/xml. If your post data is different, set the type accordingly.
Also i am using *NSURLConnection -> sendSynchronousRequest* class method to block for the response. You can also do asynchronous read of the response by creating a NSURLConnection object and setting a delegate which will listen for the incomming network events. Check the documentation for NSURLConnection .
Hope this helps,
-TRS
// This method takes an XML post data and returns the response XML from server
// Note that if you want to post binary data then just send postData instead of
// postString as input parameter
- (NSString *) postData: (NSString *) postString toURL:(NSString *) url {
NSData *postData = [postString dataUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response = nil;
NSError *error = NULL;
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = nil;
if (!error && respData) {
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
int code = [((NSHTTPURLResponse *)response) statusCode];
if (code == 200) {
responseString = [[[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding] autorelease];
} else {
NSLog(@"
Error");
} else {
NSLog(@"
Error");
[request release];
return responseString;

Similar Messages

  • I would like to use DDE to send data from a Lookout Server to an Excel

    Hello National Instruments,
    I would like to use DDE to send data from a Lookout Server to an Excel
    Spreadsheet.
    I have Lookout 6.1 on a server connected to 4 client workstations
    The operating system on the server is Windows Server 2003 R2; Standard Edition;
    Service Pack 2
    I have opened DDE Share but after filing in Share Name; Static Application
    Name; Static Topic Name
    I get a message, "Can't bind to DSDM service"
    I also get this message when I press add a Share
    What are the steps to setting up this type of communications link?
    Thanks,
    David Lopez
    Scada Functional Analyst

    Ryan,
    I have followed the steps on the Knowledge Base "How do I use DDE To Send Data Across the Network To Excel From Lookout?" but what I am seeing is that the computer with excel (Computer B)hangs up displaying an hour glass continuously leaving me no option but to go into task manager to stop excel.  It appears to me that the dde share is not working properly on my windows xp where lookout resides or I do not have a certain service turned on.  I do have the DDE services turned on both computers.  I have my computer set up as computer A with Lookout and Process1 as the process with a pot set up as pot1.  On my computer (Computer A) I also have the dde share set up per the KB example.
    On computer B I have the dde services turned on and I am typing the following into an excel worksheet Cell  ='\\TAG23232\NDDE$'|'Process1$'!Pot1
    TAG 23232 is Computer A's Name
    Do you have any suggestions???

  • "System Default" kind of wipe: possible? How would one do this?

    Would it be possible to take an existing installation and effectively reinstall all packages, restore all configuration files to their default config as if on a new install on that program, and wipe all user data (probably not in that order) so as to restore a system to a kind of "first boot" setting but with your current package listing retained.
    How would one go about this? Could one slip into a terminal, sudo rm -r /some/folders/here (what folders necessary?) and then use pacman to reinstall ... everything (what kind of command would get you that? something with a grep listing?)

    karol wrote:
    r3bel wrote:
    karol wrote:
    Unless you use a ton of system-wide configs ;P
    The problem of using a backup or hard drive image of your pristine installation is that Arch changes pretty fast and a 6-month-old installation would need a bit of work to get up to speed.
    Correct me if I'm wrong but wouldnt a pacman -Syu do most of the job?
    Depends on what changed in Arch in the meantime, what changes you made and what do you mean by 'most of the job'.
    Let's say you've made your backup a couple months ago and now you want to move from grub-legacy to syslinux, install KDE and try systemd. If you revert to said backup in a month, you will have to do a few important changes "manually" because at the time of that backup you were using grub, initscripts and e.g. Gnome.
    Reverting to the "clean slate" backup, updating it and making a fresh backup once you've tested the new configuration shouldn't be much of a problem but it's not automatic. You may need to perform some manual conflict resolution etc. (see the home page).
    This is exactly why I wanted to strip the system clean and let the programs act as if this were a new install, without changing my partition table, have to download 12 gigs of data, etc. Reinstall the system without a format. Some of these changes that needed manual adjustment have caused a bit of a headache, it would be nice to have a nuclear option without having to reinstall. Especially now that AIF isn't around anymore I'd have to have a second computer to tell me what commands to run just to get things going again...

  • I uploaded a video from itunes to my iphone how can i send it to my friend?

    I uploaded a video from itunes to my iphone how can i send it to my friend

    You can't. The techical term for that is "stealing".

  • If i want to contact apple with an idea i have for a new feature for the iphone how would i do this?

    if i want to contact apple with an idea i have for a new feature for the iphone how would i do this?

    A quick google search would have revealed the answer.
    http://www.apple.com/feedback/iphone.html

  • How can One sender communication channel pick two file from two location

    Hello
    I have a requirement that how can One sender communication channel pick two file from two location.Both the file has same name...How to configure the one receiver communication channel.i dont have any IR,no mapping..Please help me...

    >
    Soumitra Sinha wrote:
    > Hello Vijay
    > I already done the adapter specific message attribute.i am getting the file name properly.but that is nothing to do with my req.i am again clearing my problem:
    > i have two folder   folder a,folder b.Both has the same file credit0002. i have two destination folder i have one sender and one receiver channel.I dont have any IR.How one sender channel can  pick file from two location and how one receiver channel can put in two location.please help me..
    Ok now I get your requirement.
    you cant achieve this -  how one receiver channel can put in two location if you dont have a dynamic configuration defined i.e Adapter specific attributes.
    easy way - involve IR mapping
    else
    have a adapter module to define your dynamic configuration.
    Ref: /people/daniel.graversen/blog/2006/10/05/dynamic-configuration-in-adapter-modules & /people/michal.krawczyk2/blog/2006/10/09/xi-dynamic-configuration-in-adapter-modules--one-step-further
    Set the dynamic directory/file name etc for your receiver adapter.

  • How can one send email-sized photo files as attachments in Mail, without the photos appearing within the email?s

    How can one send email-sized photo files as attachments in Apple Mail, without the photos appearing in the body of the email?  If it can be done, it's not at all obvious, at least not to me.  Thanks for any help you can provide.

    The "View as icon" option shrinks the photo to an icon in the sender's Apple Mail, but how it appears to the recipient varies dependingy on what e-mail client he/she uses.
    Using Apple Mail 5.0 (the Lion version) at both ends, the sender can use the "View as icon" option to shrink his view of the photo to an icon, but the recipient also using Apple Mail 5.0 still sees the full photo in line with the message text. The recipient can then use the "View as icon" option to shrink it to an icon, but I don't think that's not what jackofarabia is looking for.
    As far as I know there is no way in the current Apple Mail to do what jackofarabia wants. There should be, but there isn't.

  • How to send data back to the server

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

  • In the new Pages, how does one send an image to the background (and make it selectable)?

    How does one send an image to the background in the new Pages and how does one make it selectable?

    Also why don't TEXT to Speech short cuts established in system preferences work in the new Pages?
    I am confused (and not completely happy)

  • HT1040 I must not have chosen a hard back book when I started my project of creating a photo book. When I go to buy the book it only allows a small soft cover book. How would one go about changing it to a hard back book?

    I must not have chosen a hard back book when I started my project of creating a photo book. when I go to buy the book it only allows me to buy the small soft cover book. How would one go about to chage the settings?

    What version of iPhoto?
    THe basic answer to duplicate the book as things may change when you change size, select themes again and pic the cover and  size you want -
    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
    LN

  • If i have a mac book 11 how would i up date the software so i can buy imovie 12 or 13

    If i have a mac book 11 how would i up date the software si i can get imovie 12 or 13

    iMovie 11 is the newest version publicly available at this time.
    (89754)

  • TS3274 how would i send my pictures from my ipad to my laptopo or computor via blue tooth?

    Hi guys...
    How would i send my pictures from my Ipad to my laptop/computer via blue tooth?

    Good afternoon
    Apple devices do not support Bluetooth file transfer.
    You can use iTunes or Photostream (if you have iCloud up ad running on both devices).  You can also send your Photos directly to apps such as Dropbox.
    Hope this helps

  • I'm trying to locate my iPhone but I didn't set up find my iPhone how would I locate it?

    I'm trying to find my iPhone but I didn't set up find my iPhone how would I locate it

    Welcome to the Apple Community.
    You can only locate, lock or erase your device when it is logged into iCloud and 'Find My Phone' is enabled, additionally the device will need to be switched on and connected to a wifi or cellular network.
    Unfortunately, you cannot activate iCloud or 'Find My Phone' remotely.

  • How would one skip from point to point that the video is changing while editing.

    How would one skip from point to point that the video is changing while editing, like if a certain set of pixels changed to white, and then mark it.?
    Basically, I have a set camera, and when certain objects change color I want to mark it.   Think of a baseball flying through the air off a pitchers hand, and be able to skip to each point the pitcher is in that position.

    The only method of this level of content analysis I'm aware of is with your eyes.
    You'll just have to wacth the video to find those parts.

  • Send Data back to the Server

    Hi.
    how to send data back to the server using J2ME or how to communicate with server using J2ME

    i am using http its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
         try {
    getGrade(url);
         } catch (IOException e) {
         System.out.println("IOException " + e);
         e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);

Maybe you are looking for

  • Error message when viewing site in IE on PC

    I've designed a site for a client using Muse. The site works great in all the Mac browsers and Chrome and Firefox for PC. When viewing it using IE, I get an error message (attached) when going from the home button to a certain page. The rest of the s

  • "Cookies" question-security problem?

    Hi all! I am having difficulty with one particular website - Spirit Airlines. Every time I try to get on it sends me to a page stating that I will not accept cookies and I need to lower my security. I have checked the preferences in Safari as far as

  • [Solved] Screen resolution problem in a qemu guest

    Hi, I have a problem with my arch os on qemu : there is a black line (near 100 pixels high) on the bottom of the virtual screen, and when i put the cursor on the bottom the screen slide (I don't see the top part of the virtual screen). I use "-vga qx

  • Value help in freestyle

    Hi, I am trying to do value help in free style mode. I am using the following tag. <THTMLB:INPUTFIELD tag id = helpinputfield = helpoutput vield= value= Markup/Result  Please telll me what should I provide for value? Why sould we give in this format

  • Import Failed loading Material Classification data Links

    Hi Friends Please help me in solving the issue. I am doing Data Migration, The data is provided in Excel sheet.All the data related to Material is imported successfully in MDM. But the Material Classification links ( 40K+ rows )  is throwing Import f