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?

Similar Messages

  • 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!

  • 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.

  • Sockets work on localhost but not remotely?

    hi there,
    I have created a simple multithreaded client / server program.
    The Server listens on port 2222 for clients. When a client connects - the client sends its ip address to the server and then disconects. More than 1 client can connect at the same time to the server and the server also listens continuasly. I have 2 problems with the program...
    a) the programs work on localhost but not on remote machines? (Well not over my LAN anyway).
    b) I am getting 2 lots of 'datain' when the server recieves an ip address from the client when the client should only send it once.
    The code is below - any help would be greatly appreciated.
    //TCPServer.java
    import java.io.*;
    import java.net.*;
    class TCPServer {
         public static void main (String args[]) throws IOException {
              ServerSocket serverSocket = null;
              boolean listening = true;
              try {
                   serverSocket = new ServerSocket(2222);
              } catch (IOException e) {
                   System.err.println("Could not listen on port: 2222");
                   System.exit(-1);
              System.out.println("Server Started...\n");
              while (listening)
              new TCPServerThread(serverSocket.accept()).start();
              serverSocket.close();
    //TCPServerThread.java
    import java.net.*;
    import java.io.*;
    public class TCPServerThread extends Thread {
        public Socket socket;
        public TCPServerThread(Socket socket) {
         super("TCPServerThread");
         this.socket = socket;
        public void run() {
                   try {
                   BufferedReader datain = new BufferedReader (new InputStreamReader
                        (socket.getInputStream()));
                        System.out.println("ip address recieved");
                        System.out.println (datain.readLine () + "\n");
                   } catch (IOException e) {
                        System.err.println("Cannot read in ip address\n");
                        e.printStackTrace(); // show the error
                        System.exit(-1);
         } //TCPClient.java
    import java.io.*;
    import java.net.*;
    class TCPClient {
         public static void main (String args[]) throws Exception
              String hostname;
              int portNumber;
              String portString;
              BufferedReader inFromUser =
                   new BufferedReader (new InputStreamReader(System.in));
                   System.out.println("What host would you like to connect to?");
                   hostname = inFromUser.readLine();
                   System.out.println("What port would you like to connect to?");
                   portString = inFromUser.readLine();
                   portNumber = Integer.parseInt(portString);
                   System.out.println("Connecting to port " + portNumber + " of " + hostname + "....\n");
                        Socket clientSocket = new Socket(hostname, portNumber);
                        Socket sock = new Socket (InetAddress.getLocalHost(), portNumber);
                        BufferedWriter dataout;
                        java.net.InetAddress i = java.net.InetAddress.getLocalHost();
                        System.out.println("Sending ip address...\n" + i.getHostAddress());
                             dataout = new BufferedWriter (new OutputStreamWriter (sock.getOutputStream()));
                                  dataout.write (i.getHostAddress());
                                  dataout.flush();
                                  sock.close();
                                       clientSocket.close();
                             }Oh, yeah - check out my site below, I am trying to write an audio streaming client / server in Java if anyone is interested in getting involved or just being nosey....
    http://www.projectg.dsl.pipex.com

    In your client you are creating two sockets (why?). One connected to localhost, the other connected to the host specified using readLine.
    If your client runs on the same machine you have started your server, you have two connects to your server instead of one.
    The ip adresse is sent using the socket connected to localhost. That is why it does not work on remote machines.
    Hope this helps.
    Jörg

  • 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?
    >

  • 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!

  • 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!

  • 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

  • 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

  • QTSS Works on Mac but not the other

    I have a Server running OS X Server 10.5.8. I am running QTSS and Apache on this machine, however I am having issues with Quicktime streaming. One mac here is able to successfully stream but all other macs on our network fail to connect despite the QTSS "Connections" window shows the connection to the machine trying to stream the video. In the end on the client Quicktime X shows "Not Found" however I am able to connect to the server via other services (ARD, AFP, HTTP). I can post any logs that might help.
    Thanks in advance

    I couldn't remember what the Display Preferences had said when we tried this last spring and again in the summer, so tonight we connected it again, and wouldn't you know - it worked just fine. We didn't do anything different, so I have no clue as to why it worked this time but not before. He's thinking about getting his own big display, but didn't want to waste his money if he couldn't get it to work, so now I guess we're shopping for another 23" display - probably a used one. Thanks!

  • Published interactive project works in IE but not in Chrome???

    My buttons and interactions are working through an Internet Explorer browser, but loose their functionality when play via Chrome. Anyone have any ideas?

    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

  • I was using webrtc connection for a video connect. Firefox works in Mac but not work in windows

    I was using our company API tokbox SDK to do the servers test between two machines. I blocked one machine ipfw to test the server connection. However, our server connection works well when we are using two mac firefox browser, but not succeed when we were using one windows and one mac machine.

    Oh, I replied in your second question here: https://support.mozilla.org/questions/1001511

  • Tiger Server: Default MySQL works for phpMyAdmin but not command line ? ? ?

    Greetings all,
    I followed the excellent instructions at
    http://discussions.apple.com/thread.jspa?threadID=132783&tstart=0
    on upgrading PHP to version 5 and getting (the preinstalled) MySQL setup with phpMyAdmin
    I can connect through the phpMyAdmin, create new dbs, etc. Problem is that now I CAN'T connect from the command line. (I originally set my new root password from the command line and that's the last time I could connect from there!
    Now I get the dreaded ERROR 2002 when I attempt:
    /usr/bin/mysql -h localhost -u root -p
    If I use the IP address or hostname instead of "localhost" (after -h) I get a ERROR 2003. Dropping the -h and hostname from the line above still gets me a ERROR 2002.
    My phpMyAdmin config is a connect type "TCP" not socket, which might be one reason it works and the command line doesn't, but I still don't know where I've gone wrong.
    My /var/mysql/* is all owned by mysql and group www.
    I'm finding lots of people asking about the ERROR 2002, but not finding any solutions (particularly for Tiger Server). I'd prefer to use the preinstalled MySQL to installing a new installation (the thread referenced above says upgrading or removing the MySQL installation is too hard to do) and there has GOT to be a reasonable explanation for why it works with phpMyAdmin, but not the command line.
    Thanks in advance for any replies!
    Many   Mac OS X (10.4.3)  

    You know what? I think when I started mysql_safe, I did it with sudo. Maybe that is my problem?
    If so, what user do I want to start it as? I've seen one suggestion of doing this:
    ./bin/mysqld_safe --user=mysql &

  • After "upgrade" to new firefox, bookmarks didn't transfer. Help tells how to import from another browser but not old firefox. Also my anti virus (latest update) apparently not compatible with 4.0 Can I restore my old version

    Question
    After "upgrading" to new firefox none of my bookmarks are in new bookmarks help topics tell me how to import from another browser but not from previous version of firefox. Another problem is my anti virus ( most up to date) is apparently not compatible with 4.0 liked the old firefox would never have "upgraded" had I known my anti virus wouldn't work. Can I get old version back

    Check with Kaspersky as to what versions of Firefox their programs are compatible with. It is up to Kaspersky to keep their stuff up to date as Mozilla releases new versions of Firefox. And if they are unwilling or incapable of doing it, they should inform their customers of such and maybe refund their customers instead of stringing them along.
    http://forum.kaspersky.com/

  • Couldn't find the adequate forum.  I run win 8.1 and the adobe acrobat dc ap on my computer edoesn't acess the doc  cloud.  I can´t turn the mobile link on.  I can acess the clud from my browser, but not from the desktop ap.  I can acess from my mobile ap

    couldn't find the adequate forum.  I run win 8.1 and the adobe acrobat dc app on my computer doesn't access the doc  cloud.  I can´t turn the mobile link on.  I can access the cloud from my browser, but not from the desktop app.  I can access from my mobile app.

    Can you please post a screenshot of your Acrobat DC when launched, without opening a PDF?
    Thanks,
    -Amboo

Maybe you are looking for