Unable to access URL using HttpURLConnection

Hi,
I am using HttpURLCOnnection class to post a data to a url(which is a web service). The webservice accepts data as text/xml.
Following is the code snippet i used:
URL url = new URL("http://xxx.xxx.xx.xx:8080/SampleWebService.svc");
HttpURLConnection conn =(HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","text/xml");
String urlStr="param1="+URLEncoder.encode(value1)+"&param2="+URLEncoder.encode(value2)
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(urlStr);
wr.flush();
InputStream in2 = conn.getInputStream();
in2.close();
wr.close();
But when i execute the code, I am getting following error at the line(InputStream in2 = conn.getInputStream();)
java.io.IOException: Server returned HTTP response code: 400 for URL
Can someone please suggest a solution. Am i missing something here?
Thanks in advance

This may not be the cause of the problem, however I will point out that the Content-Type you are setting (text/xml) is not the content type you are sending (key=value&key=value...).
If the webservice only accepts text/xml, then this is probably the cause of your problem.
Another thing you could try is removing the line that sets the content type.
Here are the request properties in some (hacky) code that I have used for sending POST requests:
               conn.setDoOutput(true);
               conn.setRequestProperty("Host", url.getHost());
               conn.setRequestProperty("Referer", referer);
               conn.setRequestProperty("Cache-Control", "max-age=0");
               conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)");
               conn.setRequestProperty("Cookie", cookies);Edited by: 842408 on Mar 7, 2011 10:14 AM
Edited by: 842408 on Mar 7, 2011 10:14 AM

Similar Messages

  • Ask your question.PPC Mini running 10.4.11 unable to access urls based on Javascript.  Software up to date.  Cannot find where to verify if JavaScript turned off.

    PPC Mini running 10.4.11 unable to access urls based on Javascript, get "Javascript void" at bottom of window..  Software up to date.  Cannot find where to verify if JavaScript turned off.

    I guess I verified this in following earlier IIIasss recommendations (whom I will respond to in detail after this).
    I have used Firefox (cookies deleted after each session) successfully with this site (Zinni Optical), but something has changed over the last year and a half and, to my knowledge it isn't on my end.  When I get response at all, and try to navigate to "My Favorites, etc., and nothing happens for a while, I try to refresh, only to get a "stopped" message with a blank screen.
    Tried Safari and Internet Explorer browsers (all I presently have installed) without succerss.  May go back to TenFourFox (which had it's own wierdness over time, which is why I uninstalled it.  Don't know latest versions compatible with 10.4.11 of Safari (but Software update is satisfied I'm up to date) or Internet Explorer.
    I'm out in the sticks using a Verizon (Novatel) MiFi in a metal building, and so require a Wilson external antenna, liightening arrestor, signal amplifier and inside rebroadcast antenna to boost cell phone  signal from one to four bars.  Hope I get similar boost for  wireless-Airport connection, understand that is different frequency, but also boosted.
    The site for the bank I do WebBillpay with has had a minor change...no longer do I get the option to sign off (six months to a year ago), otherwise, fine.

  • Unable to access website using home network but able to access using school network.

    Hi, I'm currently on a MacBook Pro running OS X Mountain Lion and Safari v6.0.4.
    As per the title, I'm unable to access particular websites, namely abduzeedo.com and fromupnorth.com, using my home network but when I try to access using my school network, I can access it freely.
    The error message I get is: "Safari can't open the page [website] because the server where this page is located isn't responding"
    I've tried clearing my cache, resetting my IP, deleting the library file (or whatever it was that some people suggested in forums) but it still doesn't work ):
    Any suggestions?

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, or by a peripheral device.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including Wi-Fi on certain iMacs.  The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • Unable to access Internet using a Mobile Network

    Hello friends
    I recently updated my SE Xperia mini pro 17i (2011 model) to ICS, initially there were some issues and I had to re-update it to finally get authentic interface of ICS. Even after the successful update I am unable to use the mobile network to access Internet, the only way  is to use a Wifi instead. Can somebody please help me out with this issue?
    Karan

    The first thing I would advise doing is contacting your current network provider and have them send you through the relevant internet settings.
    What are your thoughts about this forum? Let us know by doing this short survey.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • Unable to access url outside the machine

    Hi All,
    when i m trying to runing my web Object project (WO 5.4) the URL bing generated is :-
    http://127.0.0.1:4002/cgi-bin/WebObjects/Test.woa
    The web Object is not generating the URL consisting of System IP (Eg 192.168.3.103)
    Due to which I am unable to aceess the application through other machines.
    When I run the this application on WO 5.2 it generates URL:-
    http://192.168.3.103:4002/cgi-bin/WebObjects/Test.woa
    Please tell me the way how i can get this type of URL,So that I can access my application thorough other machine.
    I m running my application through eclipse,details are mentioned below:
    Eclipse Version: Juno Service Release 1
    java version: 1.6.0_18
    WebObject Version = 5.4.3
    Thanks!!!
    Regards
    Mritunjay

    Hi
    The error you typed is not enough. Can you please give us more information about error in log. (wls and application log)

  • Unable to access sysvol using path \\domain.local\sysvol

    Hi,
    We found that our newly configured workstations were unable to read/apply GPOs. Upon checking, we are able to access the path \\domain.local. However, when trying to open sysvol folder (or any other shared folder on the domain controller), we receive the
    following error:
    We cannot also access the folders when using domain netbios name. Strangely enough, when using IP address or DC name, we can successfully map the sysvol folder.
    Have also tried running DCdiag and the test
    NCSecDesc fails with error:
    Hope anyone can shed some light on what went wrong.
    Thank you.

    Hi,
    Based on your description, please make sure that TCP/IP NetBIOS Helper, Netlogon, and the Remote Procedure Call (RPC) services are started and set to Automatic.
    If the issue persists, we can also try disjoining and rejoining the workstation.
    The following thread focused on the similar issue and can be referred as reference.
    Cannot access
    \\domain\sysvol
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/c58600d7-5c7b-4cbb-9da4-4c98e3fa2997/cannot-access-domainsysvol?forum=windowsserver2008r2general
    Best regards,
    Frank Shen

  • Unable to access files using search title and link

    Once a list of search results appears, I am unable to retrieve the referenced document using either the hyperlink title or "link" hyperlink. I can only access the document using cache. Does crawler configuration need to be modified?

    file://localhost/dbadmin
    And here is the error message that appears when the title hyperlink is selected:
    java.io.IOException: \dbadmin\projects\NMAX_Refresh\Requests\NMAT_20050329\mtch_users_synonym.sql is not an acceptable relative path when user.dir is C:\ORACLE\PRODUCT\10.1.6\SES1\ at oracle.aurora.java.io.OracleIO.transformRelative(OracleIO.java:65) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:103) at oracle.search.GetPage.readFileURL(GetPage.java:958)

  • Unable to access Calender using Groups (as Manager) using PC

    I own a mac, but I'm doing the following on a friends PC. (That might be important to know or not).
    I went to my mac.com account and created a group. First time. When I was in my group, i clicked on the calendar area thinking it would open up and I could begin to enter data into the calendar. But, it didn't open.
    Instructions at mac.com help section state to click on a link titled "Change Calendar" located below the Calendar. But when I do that, the link changes to "learn how to create a custom calendar" link. Contrary to what the help page said, there was no option to create a custom calender. When I clicked on the "learn how to create a custom calendar" I was directed to the Group's iCal help page located at
    http://www.mac.com/1/ical.html
    According to that help page, I'm suppose to to click on the link below the calendar "change calender". (oh oh, I'm going in circles).
    Does anyone know how I can access the calendar in the Groups?
      Mac OS X (10.4)  
      Mac OS X (10.4)  
      Mac OS X (10.4)  
      Mac OS X (10.4)  

    Welcome to Apple Discussions!
    From the Groups FAQ:
    Q: How do I publish a calendar for a group?
    A: You create and publish the calendar using iCal. You can then use either the Edit Group page or the group page to select the calendar from your list of published calendars and make it available to the group via the group page.
    Because you can only create a calendar in iCal, which only runs on a Mac, you'll need to do that part from a Mac.

  • Unable to access Oracle using ODP

    Hello,
    I recently installed ODP and am trying to use it to access my Oracle 10g database from a C# Application built with Visual Studio 2005. (I can access the database via OLE with no problem). I've added the proper references and the program compiles fine. The following code failes on the call to ExecuteReader, with the message that the connection must be open. However, the call to dbConn.Open(); is successful, and as far as I can tell the connection is open (I can successfully read the database version number). Any ideas?
    OracleConnection dbConn = new OracleConnection(
         "Data Source=myDBAsInTNSNamesFile;" +
         "User Id=myuserid;" +
         "Password=mypassword;");
    try
    dbConn.Open(); //OK!
    catch (Exception)
    return false; //Never gets here
    OracleCommand cmd = dbConn.CreateCommand();
    cmd.CommandText = "Select name from people";
    OracleDataReader reader = cmd.ExecuteReader(); //FAILS! Claims connection is not open
    //etc.

    I'm not using that version of ODP.NET so I'm not altogether certain but your problem seems similar to the one described in this post...
    Oracle Technology Network: Forums
    After upgrading to ODP.NET 10.1.0.400 existings Apps fail.
    ..except your post implies that you hadn't previously tried an earlier version, so I don't think it's a problem with the assembly reference version. Still, are you sure that you've got the path references correctly configured? Did you try rebooting after the installation and setup? Also, just curious...are you encountering this problem with both win forms and asp.net applications?

  • Unable to access URL for a webservice in weblogic integration server

    Hi
    I have an application in which i deployed a webservice , however when i am trying to access it , it throws the exception weblogic.webservice.tools.wsdlp.WSDLParseException . "failed to retrieve WSDL from URL"

    Hi
    The error you typed is not enough. Can you please give us more information about error in log. (wls and application log)

  • Unable to access files using FilePermission class .

    Hi frineds !!!
    I m new to java networking..plz help in finding the solution of my problem*..Its urgent !!*
    FilePermission perm=new FilePermission("D:/contacts","read");
    AccessController.checkPermission(perm);
    and it is giving an error :
    Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission D:/contacts read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at test.Main.main(Main.java:38)
    plz help me out...

    amit.trical wrote:
    But it should grant me the permission.Are you saying you think that creating the FilePermission object should grant the permission? Or are you saying that calling the checkPermission method should grant the permission?
    Neither of those are true. Creating the FilePermission object gives you something about which you can ask if it's permitted or not. And calling the checkPermission method asks that question.
    To grant the permission to read that file, you must do that via the policy file. Java code can't grant itself any permissions (for obvious reasons).

  • Cannot access bookmarks using Safari on I-Phone

    I am suddenly unable to access bookmarks using Safari on my I-Phone. When I press the Bookmarks icon in the toolbar at the bottom, it doesn't come up with my bookmarks but shows another toolbar instead with a single button on the left hand side called "Edit". Bookmarks are all there and accessible when using Safari on my computer and have been imported to my I-Phone. The "Send webpage as URL" icon also doesn't do anything, neither does the "Home" icon. "previous" and "Next" icons do work.

    Turning off wouldn't help because settings would remain even after you restarted. So contact your email provider and them for the correct settings.

  • Handling complex URLs with HttpURLConnection

    The problem I am facing is that when I try opening a complex URL using HTTPUrlConnection, I get a Bad Request Error.
    For eg: f the URL is simple (as shown below) the code works fine.
    URL urlPage = new URL( "http://www.google.com" );
    HttpURLConnection hucnCon = ( HttpURLConnection ) urlPage.openConnection();
    But if the URL conatins some special charcters like
    "http://www.google.com/search?q=HTTPURLConnection+Example&hl=en&start=30&sa=N"
    I get a bad request page.
    I had be grateful if somebody could provide me with a solution to this.
    Thanks

    Hi ,
    Thanks for the posting but if I dfo this
    URL urlPage = new URL( URLEncoder.encode("http://www.google.com/search?hl=en&q=dcm&btnG=Google+Search") );
    I end up getting a malformedURLException.
    Thanks

  • Security error accessing url (Unable to load WSDL)

    Hi folks.
    I have a Flex project that use a WCF webservice. In my localhost everything is allright, but I want to upload my flex project to a web host (http://www.dorj.ir) and upload my WCF webservice to a server that has a valid IP...
    After going to http://www.dorj.ir, you can see this error
    Security error accessing url
    Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (http://ip/service.svc?wsdl)
    I put the crossdomain.xml file in the root of my server:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
         <allow-access-from domain="http://www.dorj.ir" />
         <allow-http-request-headers-from domain="http://www.dorj.ir" headers="SOAPAction"/>
    </cross-domain-policy>
    But I have the same error, yet...!
    what should I do?!

    Have you seen this blog
    "Crossdomain.xml" in ABAP Web AS Server cache

  • Xcelsius error: Unable to load URL while using QAAWS on XI 3.0.

    Hi Experts,
    I am getting "unable to load url" in xcelsius 2008 while importing a qaaws url.
    After all the testing below are my observations:-
    1) This has something to do with QAAWS.
    2) When I logged into QAAWS and tried accessing the newly created url from the browser. It gave this error " can not communicate to the server mcc69u01:6400" but intrestingly the cms port is located at 6464 and not 6400.
    3) For every other application like infoview and cmc it picks the correct port i.e. 6464.
    4) Server is present on a UNIX box.
    5) I read somewhere that I need to make changes in the dsws.properties file under war files folder. There I enetered "domain= mcc69u01:6464" and restarted TOMCAT.
    6) After making this change I was unable to even log into QAAWS as it gave the error 02718 " you are not authorized to create query".
    7) After reverting the changes now I am able to log into QAAWS and create new queries but the same problem persist.
    8) TOMCAT is listening to port 8088 for our environment.
    9) Tried the same thing from a different client machine with fairly new BO XI 3.0 client installation(same server) but no success.
    I believe somehow QAAWS is not able to connect to the correct port 6464 and that is the reason for this issue.
    Could anyone suggest what I should do???
    Thanks in anticipation,
    Anshul

    hi Anshul,
    The QAAWSservletprincipal is not related to how you log into the server when creating queries
    It is used when the queries are actually running, or when you are trying to load the query to a tool like Xcelsius. I had the same unable to load error and it was caused by the QAAWSservletprincipal being set to concurrent licence when my server was all named users.
    I think the issue you are seeing is more likely a bug caused by hardcoded cms port, but I think it is worth ruling out.
    Regards
    Alan

Maybe you are looking for

  • Duplicate javascript references appearing in HTML files

    Every time I run Generate | Primary Layout (Webhelp) on my Robohelp projects, I see duplicate references to a number of Robohelp built-in javascript script files in the head section of my HTML files.  For example: <script type="text/javascript"  lang

  • Setting mail notifications in Hyperion Planning 9.3.1

    I have tried setting up the email notifications in Hyperion Planning 9.3.1 version There are 3 settings that needs to be changed: 1) Advanced Settings in Hyperion Planning 2) Notifications in Hyperion Workspace 3) Set provisions in Hyperion Shared Se

  • Weblogic 8.1 sp4 console problem

    Hi I have installed Weblogic 8.1sp4 on my Windows XP professional machine. But there is a problem with the console. The left side of the console, which shows the tree structure is disabled. I can see the initial tree structure, but when I click on an

  • ZOOM questions

    Hi, Is it possible to allow ZOOM_IN but to disable ZOOM_OUT? I don't want to get a graph with a larger than the inital range - I would rather prefer providing a 'reset zoom range' button instead of having the user zoom out repeatedly What triggers ZO

  • No weather or stocks update

    Hello. I have two iPhones that I purchased at the same time. Because of crashing apps issues last week, I completed a complete reset of both phones back to the original state. Then I installed minimal apps, and installed 2.02 today. Both phones show