Javascript to Objective-C

  • Hi All,

    I am a newbie in URLLoading system in Cocoa. I got a requirement for
    converting some javascript code to Cocoa (Objective-C).

    I tried to implement by studying URL Loading System (Cocoa), but I
    couldn't get the result. Please help me in converting this js  code
    to Objective-C (Cocoa).

    Here is my Javascript code:

    var xmlReq = NewHttpObject();
    var date = new Date();
    xmlReq.open("POST", "abc.cgi", false);
    xmlReq.setRequestHeader('Content-Type', 'text/html;  charset=UTF-8');
    xmlReq.send("&command="+command+"&date="+date);

    var result = xmlReq.responseText;


    Thanks,
    Kishore
  • Are you trying to run the Javascript code through
    Cocoa, which I would recommend using a WebView, or are
    you just trying to port the code over to Obejctive-C?

    --- Kishore <kishore...> wrote:

    > Hi All,
    >
    > I am a newbie in URLLoading system in Cocoa. I got
    > a requirement for
    > converting some javascript code to Cocoa
    > (Objective-C).
    >
    > I tried to implement by studying URL Loading System
    > (Cocoa), but I
    > couldn't get the result. Please help me in
    > converting this js  code
    > to Objective-C (Cocoa).
    >
    > Here is my Javascript code:
    >
    > var xmlReq = NewHttpObject();
    > var date = new Date();
    > xmlReq.open("POST", "abc.cgi", false);
    > xmlReq.setRequestHeader('Content-Type', 'text/html;
    > charset=UTF-8');
    > xmlReq.send("&command="+command+"&date="+date);
    >
    > var result = xmlReq.responseText;
    >
    >
    > Thanks,
    > Kishore
    >

          ____________________________________________________________________________________
    Be a better pen pal.
    Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
  • I am trying to port the code over to Objective-C.

    On 03-Dec-07, at 1:21 PM, Ian was here wrote:

    > Are you trying to run the Javascript code through
    > Cocoa, which I would recommend using a WebView, or are
    > you just trying to port the code over to Obejctive-C?
    >
    >
    >
    > --- Kishore <kishore...> wrote:
    >
    >> Hi All,
    >>
    >> I am a newbie in URLLoading system in Cocoa. I got
    >> a requirement for
    >> converting some javascript code to Cocoa
    >> (Objective-C).
    >>
    >> I tried to implement by studying URL Loading System
    >> (Cocoa), but I
    >> couldn't get the result. Please help me in
    >> converting this js  code
    >> to Objective-C (Cocoa).
    >>
    >> Here is my Javascript code:
    >>
    >> var xmlReq = NewHttpObject();
    >> var date = new Date();
    >> xmlReq.open("POST", "abc.cgi", false);
    >> xmlReq.setRequestHeader('Content-Type', 'text/html;
    >> charset=UTF-8');
    >> xmlReq.send("&command="+command+"&date="+date);
    >>
    >> var result = xmlReq.responseText;
    >>
    >>
    >> Thanks,
    >> Kishore
    >>
    >
    >
    >
    >
    > ______________________________________________________________________
    > ______________
    > Be a better pen pal.
    > Text or chat with friends inside Yahoo! Mail. See how.  http://
    > overview.mail.yahoo.com/
    >

    Thanks,
    Kishore
  • I'd highly recommend checking out NSURLConnection,
    NSMutableURLRequest, NSURL, NSDate, and NSString in the Xcode
    documentation, or at developer.apple.com.

    Just off the top of my head (disclaimer: I'm typing this in Mail)...

    NSDate *now = [NSDate date]; // gives you the current date
    NSString *urlString = [NSString stringWithFormat:@"www.yourserver.net/abc.cgi&command=
    %@&date=%@", command, now]; // note:  this requires that you have an
    NSString called "command" somewhere     before this.
    NSMutableURLRequest *request = [NSURLRequest requestWithURL:[NSURL
    URLWithString:urlString]]; // note: I'm fairly certain this will only
    work if you upload the cgi script to a server, or enable web sharing
    on     your computer.
    [request setHTTPMethod:@"POST"];
    // I'm not sure what the "false" does in your third line.
    [request setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];

    Then look at the documentation for NSURLConnection for information
    about how to send the request and receive the response(s) to it.  If
    you want it to be asynchronous you're going to have to specify a
    delegate; if you're not sure what that is read http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals
    /CommunicatingWithObjects/chapter_6_section_4.html

      .

    -Sam

    On Dec 2, 2007, at 11:55 PM, Kishore wrote:

    > I am trying to port the code over to Objective-C.
    >
    >
    > On 03-Dec-07, at 1:21 PM, Ian was here wrote:
    >
    >> Are you trying to run the Javascript code through
    >> Cocoa, which I would recommend using a WebView, or are
    >> you just trying to port the code over to Obejctive-C?
    >>
    >>
    >>
    >> --- Kishore <kishore...> wrote:
    >>
    >>> Hi All,
    >>>
    >>> I am a newbie in URLLoading system in Cocoa. I got
    >>> a requirement for
    >>> converting some javascript code to Cocoa
    >>> (Objective-C).
    >>>
    >>> I tried to implement by studying URL Loading System
    >>> (Cocoa), but I
    >>> couldn't get the result. Please help me in
    >>> converting this js  code
    >>> to Objective-C (Cocoa).
    >>>
    >>> Here is my Javascript code:
    >>>
    >>> var xmlReq = NewHttpObject();
    >>> var date = new Date();
    >>> xmlReq.open("POST", "abc.cgi", false);
    >>> xmlReq.setRequestHeader('Content-Type', 'text/html;
    >>> charset=UTF-8');
    >>> xmlReq.send("&command="+command+"&date="+date);
    >>>
    >>> var result = xmlReq.responseText;
    >>>
    >>>
    >>> Thanks,
    >>> Kishore
    >>>
    >>
    >>
    >>
    >>
    >> ____________________________________________________________________________________
    >> Be a better pen pal.
    >> Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
    >>
    >
    > Thanks,
    > Kishore
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today