Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in the code below if i hit this url from browser it return me back with pop up java script require username and password but if i call it from java it return me with


Exception in thread "main" java.io.IOException: Server returned HTTP response code: 401 for URL sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
	at java.net.URL.openStream(URL.java:1045)
	at jaxbapp.JaxbAPP.main(JaxbAPP.java:29)

so how i send username and password and consume this soap service from java

What I have tried:

URL url = new URL("http://serverurl:port/sap/bc/srt/wsdl/flv_10002A111AD1/b/stp/bc/srt/rfc/sap/zsd_mob_get_cust/110/zsd_mob_get_cust_serv/zsd_mob_get_cust_bind?x-client=110");
                   HttpURLConnection con = (HttpURLConnection) url.openConnection();
               con.setDoOutput(true);
               con.setRequestMethod("POST");
                               con.setRequestProperty("Content-Type", "application/soap+xml;charset=UTF-8;action=\"urn:sap-com:document:sap:rfc:functions:ZSD_MO_GET_C:ZSD_RRequest");
                BufferedReader reader = new BufferedReader( new InputStreamReader(url.openStream()));
           while(reader.readLine()!=null) {
               System.out.println(reader.readLine());
           }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900