How can I send post data through nsurlrequest?

Hi.
I'm working on an application which needs to make requests to a php gateway. I tried many examples I found on google, but none of them worked for me.
First I was working with GET, and it worked just fine, but now, as I need to send more complex data, GET isn't a solution anymore. I have three params to send: module which is a string containing a php class name, method: the function in the class, and params for the function which is usually an indexed array.
The following method makes the request to the server, but for some reason, doesn't send the POST data. If I var_dump($_REQUEST) or var_dump($_POST), it turns out, the array is empty. Can somebody tell me, what am I doing wrong? Is there some kind of a sandbox, which prevents data from being sent to the? I also tried to send some random strings, which aren't json encoded, no luck. The sdk version is 5.1, and I'm using the iPhone simulator from xcode.
If it is possible I would like to solve this problem without any additional libraries (like asihttp).
And here is the code:
+(NSObject *)createRequest:(NSString *)module: (NSString *)method: (NSArray *)params
    NSString *url       = @"http://url/gateway.php";
    NSData *requestData = nil;
    NSDictionary *data  = [NSDictionary dictionaryWithObjectsAndKeys:
            module, @"module",
            method, @"method",
            params, @"params",
            nil];
    NSString *jsonMessage = [data JSONRepresentation];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [jsonMessage length]];
    [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody: [jsonMessage dataUsingEncoding:NSUTF8StringEncoding]];
    requestData     = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *get   = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];
    NSLog(@">>>>>>%@<<<<<<",get);
Thank you.

raczzoli wrote:
I'm working on an application which needs to make requests to a php gateway. I tried many examples I found on google, but none of them worked for me.
Why not?
Unfortunately, you are dealing with a number of different technologies that have been cobbled together over the years. You could write a PHP server that would respond correctly to this request, but not using basic methods like the $_POST variable. PHP was designed for HTML and true forms. What you are trying to do is make it work as a general purpose web service over the HTTP protocol. You can do that, but not with the form-centric convenience variables.
The following is a basic program that will populate the $_POST variable.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
  @autoreleasepool
    // insert code here...
    NSLog(@"Hello, World!");
    NSString  * module = @"coolmodule";
    NSString * method = @"slickmethod";
    //NSArray * params = @[@"The", @"Quick", @"Brown", @"Fox"];
    NSString * params = @"TheQuickBrownFox";
    NSString * url = @"http://localhost/~jdaniel/test.php";
    NSDictionary * data  =
      [NSDictionary
        dictionaryWithObjectsAndKeys:
          module, @"module",
          method, @"method",
          params, @"params",
          nil];
    //NSString *jsonMessage = [data JSONRepresentation];
    //NSData * jsonMessage =
    //  [NSJSONSerialization
    //    dataWithJSONObject: data options: 0 error: nil];
    NSMutableArray * content = [NSMutableArray array];
    for(NSString * key in data)
      [content
        addObject: [NSString stringWithFormat: @"%@=%@", key, data[key]]];
    NSString * body = [content componentsJoinedByString: @"&"];
    NSData * bodyData = [body dataUsingEncoding: NSUTF8StringEncoding];
    NSMutableURLRequest * request =
      [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:url]];
    //NSString * msgLength =
    //  [NSString stringWithFormat: @"%ld", [jsonMessage length]];
    NSString * msgLength =
      [NSString stringWithFormat: @"%ld", [bodyData length]];
    [request
      addValue: @"application/x-www-form-urlencoded; charset=utf-8"
      forHTTPHeaderField: @"Content-Type"];
    [request addValue: msgLength forHTTPHeaderField: @"Content-Length"];
    [request setHTTPMethod: @"POST"];
    //[request setHTTPBody: jsonMessage];
    [request setHTTPBody: bodyData];
    NSData * requestData =
      [NSURLConnection
        sendSynchronousRequest: request returningResponse: nil error: nil];
    NSString * get =
      [[NSString alloc]
        initWithData: requestData encoding: NSUTF8StringEncoding];
    NSLog(@">%@<",get);
  return 0;
I have written this type of low-level server in PHP using the Zend framework. I don't know how to do it in basic PHP and wouldn't bother to learn.
Also, you should review how you are sending data. I changed your example to send the appropriate data and content-type for the $_POST variable. If you had a server that could support something else, you could use either JSON or XML, but your data and content-type would have to match.

Similar Messages

  • How can I send purchase order through SAP mail ?

    How can I send purchase order through SAP mail ? Can any one explain whts the NACE settings?

    just  do it as  <b>Anji reddy</b> said to you   ...or else  ...  in the purchase  order trascation  ...print it  ... so that  it will generate the spool request  for that  purchase  order  ....
    so the   the belwo program is for sending <b>the Spool   Request  data   as  Email  to  any Email id  ...</b>
    The code below demonstrates how to retrieve a spool request and email it as a PDF document. Please note for the below program to process a spool request the program must be executed in background otherwise no spool request will be created. Once you have had a look at this there is an modified version of the program which works in both background and foreground. Also see transaction SCOT for SAPConnect administration.
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    * Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    * Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    * Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    * Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    * Write statement to represent report output. Spool request is created
    * if write statement is executed in background. This could also be an
    * ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    *** Alternative way could be to submit another program and store spool
    *** id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
    *        to sap-spool
    *        spool parameters   %_print
    *        archive parameters %_print
    *        without spool dynpro
    *        and return.
    * Get spool id from program called above
    *  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
    *       FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
    *       FORM get_job_details                                          *
    FORM get_job_details.
    * Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
    *       FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
    *       FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    *  perform send_email using p_email2.
    ENDFORM.
    *       FORM send_email                                               *
    *  -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    *  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
    *       FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    Girish

  • How can I send a MIDP through MMS??

    Hi there,
    I need to know how can I send a JAR through MMS,
    I'm not talking about WMA API..... please, understand that I don't
    want do send a MMS through JAVA or J2ME or MIDP.
    I want to send my compiled midp in a JAR, in a MMS.

    https://itunes.apple.com/us/app/id314894105?mt=8
    https://itunes.apple.com/us/app/id306273816?mt=8
    They have some limitations though. They have paid versions that remove those limitations

  • Im trying to send out a word doc and it tells me I need to set up an account with enterage. I already have my email set up with regular mail? How can I send it out through my email that is active?

    Im trying to send out a word document via email. It tells me it cannot send because I have not yet set up an account with enterage. My email is active already with Apple regular mail program. How can I send it out through reg mail?

    Save the Word document. Create your email in your normal mail application (Mail?), click on the add attachment icon (the paperclip if you are using Mail). Navigate to where you saved the Word file and select it. It should now appear as an attachment in your email. If you are sending it to a PC user and you are using Mail make sure 'Send Windows-friendly attachments' is selected in the edit menu. And if you don't want the attachment to display inline within the body of the email Control+Click on it and select 'view as icon'.

  • How can i send the data from WD to SMARTFROMS to fill it?

    Hi All,
    how can i send the data from WD to SMARTFROMS to fill it?
    Best Regards

    Hello
    After conferring with a colleague, the following response may help:
    The Smart Form doesn't have any special integration in WebDynpro.
    Therefore the application should implement it especially.
    Steps:
    1) Call of Smart Forms in mode GET_OTF
    2) Convert OTF to PDF
         3) Show the PDF in WD Context Node
    Similar topic was discussed here:
    Re: Displaying Smartforms in Webdynpro ABAP
    Thanks
    Kind Regards
    Toros Aledjian
    Edited by: Toros Aledjian on Nov 29, 2010 8:43 AM

  • HT2508 My amp has an USB input but when I attach my mac pro to it, and set the input to the USB setting, no sound comes out. I looked at the system settings, but none of them produce a different outcome. How can I send the music through the USB out to USB

    My amp has an USB input but when I attach my mac pro to it, and set the input to the USB setting, no sound comes out. I looked at the system settings, but none of them produce a different outcome. How can I send the music through the USB out to USB in?

    AFAIK cameras offer their own built-in format utility for inserted SD cards.  You should use that.  Otherwise, refer to the manual that came with your camera to determine precisely how your SD cards need to be formatted to work properly.  Personally, I'd suggest Partition Scheme: MBR, and Filesystem: FAT32.
    Try to limit the number of formats you perform on the SD cards, though, as you're reducing their lifespan.  I believe formatting causes re-writes to a portion of the SD card that has fewer read/write cycles than the rest of the card as a whole.

  • How can i send a document through my email with a ipod touch 2nd generation?

    How can i send a document through my email with a ipod touch 2nd generation?

    https://itunes.apple.com/us/app/id314894105?mt=8
    https://itunes.apple.com/us/app/id306273816?mt=8
    They have some limitations though. They have paid versions that remove those limitations

  • How can I send registeration data from Mac machine to NT machine?

    How can i send or post data from Mac machine to NT machine without using browser? I m stucked. I want to register a customer from Mac machine by a container i.e. Form having awt components etc. and send it to NT machine to trigger it into SQL Server. Can i use Servlet for this purpose? The problem is client machine have Mac and no browser. But host machine is NT based.

    Thanks !
    I have got that one. But its documentation API describes very little information. I could not properly follow. if there is some help to start up in HTTP client?
    Can i use classes of HTTP client in my application and why i need it, I m not following as well. Please describe reply in detail.

  • How can i send a picture through text?

    Does anyone knows how to send a picture through text message?

    I came across this a while back and thought it was a good read
    There are some interesting challenges with MMS that do not exist with SMS:
    Content adaptation: Multimedia content created by one brand of MMS phone may not be entirely compatible with the capabilities of the recipients' MMS phone. In the MMS architecture, the recipient MMSC is responsible for providing for content adaptation (e.g., image resizing, audio codec transcoding, etc.), if this feature is enabled by the mobile network operator. When content adaptation is supported by a network operator, its MMS subscribers enjoy compatibility with a larger network of MMS users than would otherwise be available.
    Distribution lists: Current MMS specifications do not include distribution lists nor methods by which large numbers of recipients can be conveniently addressed, particularly by content providers, called Value Added Service Providers (VASPs) in 3GPP. Since most SMSC vendors have adopted FTP as an ad-hoc method by which large distribution lists are transferred to the SMSC prior to being used in a bulk-messaging SMS submission, it is expected that MMSC vendors will also adopt FTP.
    Bulk messaging: The flow of peer-to-peer MMS messaging involves several over-the-air transactions that become inefficient when MMS is used to send messages to large numbers of subscribers, as is typically the case for VASPs. For example, when one MMS message is submitted to a very large number of recipients, it is possible to receive a delivery report and read-reply report for each and every recipient. Future MMS specification work is likely to optimize and reduce the transactional overhead for the bulk-messaging case.
    Handset Configuration: Unlike SMS, MMS requires a number of handset parameters to be set. Poor handset configuration is often blamed as the first point of failure for many users. Service settings are sometimes preconfigured on the handset, but mobile operators are now looking at new device management technologies as a means of delivering the necessary settings for data services (MMS, WAP, etc.) via over-the-air programming (OTA).
    WAP Push: Few mobile network operators offer direct connectivity to their MMSCs for content providers. This has resulted in many content providers using WAP push as the only method available to deliver 'rich content' to mobile handsets. WAP push enables 'rich content' to be delivered to a handset by specifying the URL (via binary SMS) of a pre-compiled MMS, hosted on a content provider's web server. A downside of WAP push is that from a billing perspective this content is typically billed at data rates rather than as an MMS. These charges can be significant and result in 'bill shock' for consumers.
    Although the standard does not specify a maximum size for a message, 300 kB is the current recommended size used by networks due to some limitations on the WAP gateway side.

  • Can't send POST data from servlet

    Hi,
    I have a servlet that receives data via GET method, process the request and then it has to send feedback to an url, but the query string that
    I have to send must be in a POST method.
    I ilustrate this:
    http://host:port/myservlet?param1=value1
    myservlet proccess and then calls
    http://external_url (with param2=value2 via POST)
    I've tried to put an HttpURLConnection
    URL url = new URL("http://localhost:7001/prueba.jsp");
    java.net.HttpURLConnection con= (HttpURLConnection)url.openConnection();
    //POST data
    URL url = new URL("http://localhost:7001/prueba.jsp");
    HttpURLConnection c = (HttpURLConnection)(url.openConnection());
    c.setDoOutput(true);
    PrintWriter out = new PrintWriter(c.getOutputStream());
    out.println("param2=" + URLEncoder.encode("value2"));
    out.close();
    but I get this error.
    lun mar 10 13:53:46 GMT+01:00 2003:<W> <ListenThread> Connection rejected: 'Login timed out after 5000 msec. The socket
    came from [host=127.0.0.1,port=2184,localport=7001] See property weblogic.login.readTimeoutMillis to increase of decreas
    e timeout. See property weblogic.login.logAllReadTimeouts to turn off these log messages.'
    (it's a weblogic 5.1 problem, i've been researching a little bit)
    And I don't want to call a jsp that generates a post form, and then it's auto-submitted with javascript. (this will be the last remedy!!)
    How can i do this?
    All suggestions will be grateful.
    Thanks in advance.
    PD: sorry for my english :)

    I make an URLConnection and I intended to know if the post data was
    sent right. Then, in my machine, under weblogic 5.1, I developed a jsp with this code:
    <%
    URL url = new URL("http://machine2/examples/prueba.jsp");
    HttpURLConnection c = (HttpURLConnection)(url.openConnection());
    c.setDoOutput(true);
    PrintWriter outd = new PrintWriter(c.getOutputStream());
    outd.println("param1=" + URLEncoder.encode("value1"));
    outd.close();
    c.disconnect();
    %>
    and in machine2 (using tomcat 4.1), I simply put a line in prueba.jsp:
    System.out.println(request.getParameter("param1"));
    and I don't get "value1" in the tomcat log as expected (I think).
    I also tried with adding this properties:
    c.setRequestProperty("Content-Length", size...);
    c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    and it didn't work!
    what's wrong?

  • How can I send an image through a WebService

    Hi,
    I'm trying to send an image through a WebService to a mobile phone, but I can't get it working.
    Anyone knows how I can send an image on the server side, and receive it on the client side?
    Thanks for your help.

    Hope this will help
    String encodingStyleURI = org.apache.soap.Constants.NS_URI_SOAP_ENC;
    SOAPMappingRegistry smr = new SOAPMappingRegistry();
    BeanSerializer beanSer = new BeanSerializer();
    try {
    // Build the call.
    Call call = new Call();
    call.setSOAPMappingRegistry(smr);
    call.setTargetObjectURI("urn:filereceiver");
    call.setMethodName("loopFile");
    call.setEncodingStyleURI(encodingStyleURI);
    Vector params = new Vector();
    DataSource ds = new ByteArrayDataSource(new File(fname),
                                  null);
    DataHandler dh = new DataHandler(ds);
    params.addElement(new Parameter("addedfile",
                             javax.activation.DataHandler.class, dh, null));
    params.addElement( new Parameter( "filename", String.class,fname, null ) );
    call.setParams(params);
    // Invoke the call.
    Response resp;
    try {
         System.out.println(url);
    resp = call.invoke(url, "");
    } catch (SOAPException e) {
              FLAG          ="NO";
              System.err.println("Caught SOAPException (" +
                        e.getFaultCode() + "): " +
                        e.getMessage());
              e.printStackTrace();
    return FLAG;
    // Check the response.
    if (!resp.generatedFault()) {
    Parameter ret = resp.getReturnValue();
    if (ret == null){
    System.out.println("No response.");
              FLAG="NO";
    else {
              // System.out.println("Response: " + resp);
    // printObject(ret.getValue());
    } else {
    Fault fault = resp.getFault();
              FLAG          ="NO";
    System.err.println("Generated fault: ");
    System.err.println(" Fault Code = " + fault.getFaultCode());
    System.err.println(" Fault String = " + fault.getFaultString());

  • How can I send picture msgs through E50

    Please help me, I dont know how to send Picture msgs through sms? can you help me?

    picture mesgs shd be mms. so, u have to have a mms activated SIM card and thats it

  • How can I change Posting Date on Sales Invoice form in UI?

    Hello,
    I cannot change the Posting Date on the Sales Invoice form in UI.
    The new date is earlier than the system date, but when I type it on the field on the form, it's not problem!
    I've tried to use the following code in vb.NET:
    SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Specific.value = DocDueDate.ToString("yyyyMMdd")
    But I've got an exception: <i>Form - Bad value</i>
    Next step I tried this, but I've got a same message:
    SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Click(SAPbouiCOM.BoCellClickType.ct_Regular)
    SBO_Application.SendKeys(DocDueDate.ToString("yyyy.MM.dd"))
    Any idea?
    THX,
    Csaba

    Hi Csaba!
    please, make sure that you've handled Sales Invoice form - just show the message:
    MessageBox.Show(pVal.FormUID)
    edDate = SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Specific
    edDate.value = DocDueDate.ToString("yyyyMMdd")
    This has to show you 133. If not then put the IF-statement to check what form you are handling before you try to get the item's handler

  • How can I send a photo through messaging without using photo stream?

    Ever since I updated my phone I can't send a pic without photo streaming and not everyone has an iPhone so I can't send pics to everyone I want to/

    Well, if you have iOS 6 on your iPhone 4, and click on a photo in your photo library, then click the "share" button in the lower left, you see these options:
    Mail
    Message
    Photo Stream (OK, you don't want that one)
    Twitter
    Facebook
    [4 other options not directly related to electronic sharing]
    So I would say you have a plethora of options.

  • How Can i send the data entered in Input text fields to e-mail?

    Iam Jennifer, Iam having a doubt in Flash, I hope that you
    are going to solve my problem, Iam taking 3 Static text fields as
    Name, Age and Country and besides each and every static text fields
    i have taken 3 input text fields with different instance names,
    when i enter my Name, Age and Country details in the input text
    fields and after entering those details if user clicks the submit
    button the data should be send to some mail address, is it possible
    Im not so good at action script, but i hope that any one can
    help me...
    Iam attaching the action script code also, please find the
    attachment below, the actions are given to button.
    Attach Code
    Btn.onPress = function ()
    mail_lv = new LoadVars();
    mail_lv.dummy1 = "";
    mail_lv.subject = "Details";
    mail_lv.message = "hi";
    mail_lv.username = "name_txt".text;
    mail_lv.age = "age_txt".text;
    mail_lv.country = "country_txt".text;
    mail_lv.onLoad = function ()
    trace("Sent successfully...");
    trace("mail_lv.subject = " + mail_lv.subject);
    trace("mail_lv.message = " + mail_lv.message);
    mail_lv.send("mailto:[email protected]", "_blank");

    The names of your variables, "name_txt", for instance, should
    NOT have quotes around them. Use:
    mail_lv.username = name_txt.text;
    mail_lv.age = age_txt.text;
    mail_lv.country = country_txt.text;

Maybe you are looking for