Exact same request works in browser but not in my app!!!

Hello all, I have an application that posts requests through an https connection to a web server. When everything goes well, the server is supposed to send me an xml file. Once my String is encoded and ready to be sent, it looks something like this:
InputSegments=%3c%3fxml+version%3d%221.0%22+encoding%3d%22UTF-8%22%3f%3e%3cCNCustTransmitToEfx+So when I send it, I receive an error from the server saying that the request is incorrect. But when I copy paste the request String to the browser, it works great!!! I tried to change requestMethod to GET, but I still get the error message from the server. So I can't figure out what is wrong here... I am posting my function hoping that somebody will be able to help me:
private static class SecuredConnectionInstantiator extends Thread
    public boolean stop = false;
    private int returnCode = -1;
    private String securedUrl = null;
    private String xmlRequest = null;
    private String outputFile = null;
    public void run()
      try
        URL objUrl = null;
        HttpsURLConnection urlc = null;
        String inputLine = null;
        StringBuffer xmlResponse = null;
        xmlResponse = new StringBuffer();
        objUrl = new URL(securedUrl);
        urlc = (HttpsURLConnection)objUrl.openConnection();
        if (urlc == null || objUrl == null)
          throw new MalformedURLException();
        urlc.setUseCaches(false);
        urlc.setDoInput(true);
        urlc.setDoOutput(true);
        urlc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
        urlc.setRequestMethod("POST");
        OutputStream out = urlc.getOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(out);
        String tmp = encode(xmlRequest);
        tmp = "InputSegments=" + tmp + "&cmdSubmit=Submit";
        System.out.println(tmp);
        writer.write(tmp);
        writer.flush();
        writer.close();
        //Si le thread n'a pas �t� intterompu, on obtient la r�ponse et on
        //l'enregistre sur disque.
        if (!stop)
          BufferedReader xmlResponseReader = new BufferedReader(new InputStreamReader(objUrl.openStream()));
          BufferedWriter xmlFileWriter = new BufferedWriter(new FileWriter(outputFile));
          while ((inputLine = xmlResponseReader.readLine()) != null)
            xmlResponse.append(inputLine + EOL);
            xmlFileWriter.write(inputLine);
            xmlFileWriter.flush();
          xmlResponseReader.close();
          xmlFileWriter.close();
          //La requ�te s'est termin�e normalement...
          returnCode = 0;
      catch (MalformedURLException e)
        //Erreur lors de l'appel...
        //returnCode = code d'erreur...
      catch (IOException e)
        //Erreur d'E/S...
        //returnCode = code d'erreur...
    }Your help will be greatly appreciated!
Alex

I solved the problem, I dont know if it's a good way to do this, but here's what I've done: Instead of opening a connection to the server and the send the request throug the stream, I open the connection and pass the request next to the server's address:
        xmlResponse = new StringBuffer();
        objUrl = new URL(securedUrl + "?InputSegments=" + URLEncoder.encode(xmlRequest, "UTF-8") + "&cmdSubmit=Submit");
        urlc = (HttpsURLConnection)objUrl.openConnection();Anyway thank you all for your help!

Similar Messages

  • HTTP POST works on browser but not socketically

    I can post info using a simple html but i cant post using sockets..
    InetAddress addr = InetAddress.getByName(hostname);
                Socket socket = new Socket(addr, port);
                String path = postpath;
                BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
                wr.write("POST "+path+" HTTP/1.0\r\n");
                wr.write("Content-Length: "+data.length()+"\r\n");
                wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
                wr.write("\r\n");
                wr.write(data);
                wr.flush();
                BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()))
    /code]
    it works on my local web server but not on the remote web server. what could be the problem and explanation?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    100% right way is to catch request from browser and create your our in same way. Completely except content length and content itself :)
    If you can't then try to:
    add Host field
    add Cookies if present
    add Referer
    add User-Agent
    Some clever servers check all these fields for some reasons (prevent silly attacks for example and successfully as I can see...)
    Then ask again.
    One more - are you sure you use correct content format? And last - how do you know it doesn't work with remote server? Exactly?

  • Search works in spotlight, but not in Mail.app

    If I type in the search box in Mail, nothing happens. The same query in Spotlight works. What can I do to fix that?
    G4   Mac OS X (10.4.9)  

    > I don't use the .mac address, but I guess it's a .mac account.
    Still not sure what you mean. It cannot be a .Mac account if it doesn’t have a .Mac address associated with it, and your mail cannot be stored on a .Mac server if you don’t have a .Mac account... What does Mail show in Preferences > Accounts > Account Information > Account Type?
    Anyway, I don’t know how to solve the problem in your case. When searching in Spotlight doesn’t work, the problem can be fixed by re-creating the Spotlight database. When searching in Spotlight works but Entire Message searches in Mail don’t, re-creating Mail’s index usually fixes the problem, but not always and I don’t know why.
    Try this to try to identify the problem:
    1. Open /Applications/Utilities/Console.
    2. From the File menu, choose either Open Console Log, or Open System Log, or both, so that Console displays the contents of both system.log and console.log.
    3. Reproduce the problem and look at the bottom of the Console windows for messages that might be written there as a result. They may provide some clues.
    <hr>
    You may try setting up Mail again from scratch and importing your mail back, but I don’t know whether that will work either:
    1. If you have a .Mac account and .Mac synchronization of Mail data is enabled either in Mail > Preferences > General or in System Preferences > .Mac, disable it before proceeding.
    2. Quit Mail if it’s running.
    3. In the Finder, go to ~/Library/. Move (not copy) the entire Mail folder out of there, to the Desktop.
    4. In the Finder, go to ~/Library/Preferences/. Locate com.apple.mail.plist and move it to the Desktop.
    5. Open Mail and set it up again from scratch. If given the option to import existing mailboxes or something like that, don’t. Just enter the account information and check that everything works fine.
    6. You’ll have to re-configure all your settings in Mail > Preferences. For spam-related security reasons, the first thing you should do is go to Preferences > Viewing and disable Display remote images in HTML messages if it’s enabled.
    7. If Mail works fine now and you had any messages stored in local mailboxes, do File > Import Mailboxes, choose Mail for Mac OS X as the data format, and follow the instructions to import your mail from the old Mail folder that’s now on the Desktop. Import the Mailboxes folder first, then each of the POP-username@mailserver account folders.
    8. If .Mac synchronization of Mail data was enabled at the beginning, enable it again, go to System Preferences > .Mac > Advanced, click Reset Sync Data, and choose the appropriate options to reset the Mail data stored on the .Mac server with the data locally stored on the computer, i.e. sync data must flow from the computer to the .Mac server.
    As a result of doing the above, some messages may be duplicated. Andreas Amann’s Mail Scripts has a Remove Duplicates script that you may find useful.
    Do with the imported mail whatever you wish. You may move the messages anywhere you wish and get rid of the imported mailboxes afterwards.
    If all is well and you don’t miss anything, the files on the Desktop can be deleted, although you may want to keep them for a while, just in case.
    Note: For those not familiarized with the ~/ notation, it refers to the user’s home folder. You can easily locate any of the folders referred to in this post by copying the folder path here, doing Go > Go to Folder in the Finder, and pasting the folder path there.

  • E71 wifi connection works in browser, but not with...

    I need help badly.
    On my Nokia E71 I can easily connect to a wireless network and browse the web from the browser. But when I try to read my Gmail from the mail client on the phone I get an error message "Unable to connect to e-mail server". The settings are correct since if I switch to GPRS/3G connection, then the client connects to the server and downloads the messages. This is weird. The same is for VoIP and Fring and Nimbuzz, they all work with GPRS/3G but they don't when I choose wi-fi.
    What's more weird is that other people in the building use their person handhelds for the above purposes. The IT guy administering the network assures me no ports are blocked and that's obvious, since people use Skype and check their emails through the same wi-fi spots in the building. I fee l am missing something easy to solve, but I can't get through. Please help!

    Hello mgoksoy,
    Thank you for your reply. The problem is not with wifi connectivity option but inability to connect to wifi. For instance, if I run Nimbuzz, the settings are set to request from me each time I start it which connection to use - gprs or wifi. I choose GPRS it works alright, I choose wifi it does not connect and gives me "socket connection failed!" error. I get the same error in other wifi networks, so this is not about one specific wireless network. The same is with other applications, when I choose wifi connection it simply does not connect, like to gmail via nokia email client, I get a "unable to connect to e-mail server" error, whereas if I connect with GPRS, it works fine. And one more important, I can connect to all wifi's and browse the web via browser. But it's just the applications that won't connect and I was thinking if there was a setting in my E71 that need to be adjusted to allow applications wifi connections.

  • Same link works on desktop BUT NOT on ipad -Help pls!

    Hello,
    I have created ONLY a desktop version of this site, www.frabricci.ca. When I check the link to the clients instgram account (seen on the home page instgram icon & last paragraph of that page, as well as last paragraph on contact page), its works on desktops and on mobile (iphone), yet when viewing the site on an ipad the link does not work. Confused to why this would happen as I've only created one site with the same link - HELP PLEASE!

    Hi
    I tried to check instgram account link from home and page and it works on iPad.
    Can you please let me know the browser details and OS details on iPad that you are using , also please check with different browser.
    Thanks,
    Sanjit

  • Webcam works in JMStudio but not in JMF apps (Linux)

    Hi everybody,
    I have successfully installed the Linux drivers (it's a Logitech Quickcam Express), and registered the webcam with jmfregistry. It works perfectly in jmstudio, both if selecting the "capture" menu or just opening an url as "v4l://0".
    However, I cannot succeed in creating a datasource for this camera in my application. I can get the MediaLocator of the device, its list of formats, but when calling to Manager.createDataSource(), a "NoDataSourceException" is thrown.
    Any hint, please?
    Thanks a lot in advance.

    Hi again,
    I have also tested the JMF code samples, e.g. VideoTransmit, and I get the same problem.
    It seems that only jmstudio is capable of using the camera!!!
    Help, please!

  • My subscription for plus is valid but I cannot access my forms in the Windows program.  I can see them by logging on with a browser but not in the app.  Air is updated.  Help.

    Need help as I prefer using the App to having to use a browser

    You can try using this tool to first remove all traces of Reader from your computer:
    http://labs.adobe.com/downloads/acrobatcleaner.html
    Then, you can download the full offline Reader installer from
    http://get.adobe.com/reader/enterprise/
    After downloading, restart your computer and run the installer before doing anything else.

  • Hello i have a problem with onfocus function on ipad. i am trying to bring my cursor on a text box on a button click. It works fine with safari web browser but not on ipad. Need a solution.

    Hello i have a problem with onfocus function on ipad. I am trying to bring my cursor on a text box on a button click. It works fine with safari web browser but not on ipad. Need a solution.

    I don't think that a software update from Apple will solve the issues that you are having. You have a rogue installation. After you posted I have just done the following:
    Disk Utility can verify  my partitioned Volume (including my boot disk) AND REPAIR the non-boot disks on the same Volume without a glitch. It repairs the non-boot disks containing data smoothly.
    I have used Mail to send some mails from some Yahoo and Hotmail accounts to my Thunderbird client containing GMail accounts - absolutely normal.
    I have iLife '09 but my iMovie '09 and iPhoto '09 open in a jiffy and I see no issues here. I have 6GB RAM (Maximum) on an early 2008 Macbook Pro with a 750GB hard drive partitioned with 120GB reserved for the Boot Drive.
    I am sorry that I cannot help further but I am sure there must be a way to reinstall the software without having to revert to restoring your ML backup. I have two clones and if you have such I would attempt to do that through that rather than through Time Machine - that is of course if you have a cloned drive.
    Good luck!

  • Flash work in preview but not in the browser!?

    Hi there:)
    I have a .swf file in a table in Dreamweaver. When I preview it in place and in Safari, it plays. When I upload eveything, it is not in any browser on the server.. any ideas?
    Thanks!
    V

    Hi John!
    Yes, sorry about that.. here it is.
    http://farmingtonfarm.com/appraisal.html
    Thanks for your help!!
    v
    Date: Thu, 8 Apr 2010 18:52:05 -0600
    From: [email protected]
    To: [email protected]
    Subject: flash work in preview but not in the browser!?
    Can't really help without a link to the site. Can you provide one?
    >

  • Some websites keep asking to enable cookies in my browser when they are and I can't get this sites to see that, they worked fine yesturday but not now, any help

    Some websites keep asking to enable cookies in my browser when they are and I can't get this sites to see that, they worked fine yesterday but not now. I've restarted the browser, restarted the computer, disabled then enabled cookies in the privacy settings and still nothing. Any help?

    Hi,
    Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
    Note: ''This will temporarily log you out of all sites you're logged in to.''
    To clear cache and cookies do the following:
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
    Did this fix your problems? Please report back to us!

  • Album Art works for most, but not all

    I was reading previous forums on the subject, but no clear answer was given..
    The album art shows up fine in itunes and my library and works for most of my music on my ipod, but how come some album's art does appear? I have it set manually and select 'Get Info' then 'Artwork' and add it from there, then drag in the finished product to my ipod. I've been doing that and it works fine for most of the albums, but every so often, the album art will not appear on my ipod. Am I doing something wrong? I take them all from the same source (amazon.com) but it makes no sense to me how some randomly don't appear.
    I tried deleting the artwork and re-adding it, but nothing happened again. If you could answer why it works for most but not all or how I can get the album art to appear for the ones it will not by re-doing something, it would be appreciated. thanks.

    I encountered the same problem in the beginning. When I compared the size of the original images, the working ones seemed to be smaller in general, so I reduced the size of all covers I intended to upload on the pod to 300x300 pixels.
    This seemed to work - for 2 days. I bought the pod on friday, had pictures on sunday, but on Monday (after the first time the pod was fully discharged) none were left left.
    So I ended searching this forum for related problems...
    And decided to join my problem to this entry.

  • Medical app from Intuit works in IE, but not Firefox.

    Encrypted medical app works in new IE, but not Firefox. Everything works down to the end, and click on "continue" and nothing happens. A tech and I have spent hours on this. Did not work on FF5 or 6. Did not work on old IE, but did on fresh new version with no data files copied in.

    If it works in IE but not FF, then it has nothing to do with the mp3s. More likely it's because of the HTML on the page.
    To start, page is missing DOCTYPE declaration... a MAJOR problem. The DOCTYPE declares which set of rules the browser will use to display the page. Without it, different browsers go crazy or do not work at all.
    http://www.w3schools.com/tags/tag_DOCTYPE.asp
    Validate the html code here:
    http://validator.w3.org/
    You will have to fix all the errors if you want this to work in all browsers.
    Best wishes,
    Adninjastrator

  • Flash Player works in Safari but not Internet Explorer 9

    I've installed Flash Player 10.3 and it works in Safari but not Internet Explorer 9. When I look in Manage Add-Ins I see Flash Shockwave but not Flash Player. My operating system is Windows Vista Ultimate (32bit). Safari is 5.0.5 and IE 9 is 9.0.8112.16421. I've tried uninstalling and re-installing Flash Player and uninstalling Norton 360. Nothing has worked so far. Can you help?

    Thank you for your reply. Shockwave is loaded and enabled.
    The files in flash directory are: a folder called FlashPlayerTrust: file, flash10q.ocx: file, FlashInstall.log; file, FlashUtil10q_ActiveX.dll; file, FlashUtil10q_ActiveX.exe, file, install.log.
    There is no file: NPSWF32.dll.
    When I test the browsers I get no spinning logo in either Safari or IE9. Safari says: missing plug-in, where I think the logo should be. IE-9 says nothing at the same location.
    Thanks.

  • Works in IE but not FireFox?

    site is here
    http://carolyoungs.myartsonline.com/
    when i hosted it on a different server it worked in both browsers, now i changed to a different free host because of the mp3 file i have with the site, and some sites will not host mp3 and it only works with IE
    can anyone help me out?

    If it works in IE but not FF, then it has nothing to do with the mp3s. More likely it's because of the HTML on the page.
    To start, page is missing DOCTYPE declaration... a MAJOR problem. The DOCTYPE declares which set of rules the browser will use to display the page. Without it, different browsers go crazy or do not work at all.
    http://www.w3schools.com/tags/tag_DOCTYPE.asp
    Validate the html code here:
    http://validator.w3.org/
    You will have to fix all the errors if you want this to work in all browsers.
    Best wishes,
    Adninjastrator

  • Spry form validation working in IE but not in Firefox or...

    Ok putting together a contact us form and would like a few
    fields to be required. It works in IE7 but not in Firefox, Safari
    or Google Chrome. In IE7 I get the error msg for no valid email but
    in the other browsers it just does nothing. Here is the link to the
    page
    Aspen
    Homes
    Can anyone help with this? I have used Spry on a couple other
    site and never had an issue. I am updated to the most recent
    version also. I am running
    Vista Ultimate (64-bit)
    DW CS3 or DW CS4 (both do the same thing)
    I have attached my code here in a txt file
    Page
    Code
    thanks
    B

    Anyone?

Maybe you are looking for