p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   HttpURLConnection from Java to ASPX??? (http://p2p.wrox.com/showthread.php?t=6845)

MichaelTJ December 3rd, 2003 04:23 PM

HttpURLConnection from Java to ASPX???
 
Hi all you out there,
I'm making a page to send SMS from WEB, I've got a script in Java on how to do it.
But I'm making it in ASPX.
The first things in the script was ok to convert, but I can't find anywhere to convert
the URLConnection bit.. I've been looking around and all I could find was the
<configuration><system.web><authentication> to use in Web.config.
Is there anyway to do this in ASPX??

As always.. Thanks for all and any help out there.


********JAVA SCRIPT********************
String code = "XXXXXXXXXXXXXXXXXXXXXXXXXXXxx"

string from = "1900"

string to = "+46xxxxxxxx"

string msg = "Hello world"

String encoding = "ISO-8859-1"

StringBuffer sb = new StringBuffer();
sb.append("from" + from);
sb.append("&price=0");
sb.append("&type=text");
sb.append("&encoding=" + encoding);
sb.append("&to" = + URLEncoder.encode(to, "ISO-8859-1"));
sb.append("&data" = + URLEncoder.encode(msg, encoding));
String query = sb.toString();

URL url = new URL("http://mdfrisk.cpa.station.com:60000/sms?" + query);

****MY main problem is to do this part in VB.NET*****
//Set authorization header and request method
HttpURLConnection conn = (HttpURLConnection) url.openconnection();
conn.setRequestProperty("Authorization", "Basic " + code);
conn.setrequestMethode("GET");
conn.connect();

//Send the request and print the reply
System.out.printIn("Response code: " + conn.getResponseCode());
System.out.printIn("Response msg: " + conn.getResponseMessage());

BufferReader = br = new BufferReader(new InputStreamReader(conn.getInputStream()));
system.out.PrintIN("Body: " + br.readLine());
br.close();

------------------------
All help is Good help!
Regards
Michael

planoie December 3rd, 2003 05:59 PM

Take a look at the System.Net.HttpWebRequest class.

Peter
------------------------------------------------------
Work smarter, not harder.

MichaelTJ December 3rd, 2003 09:39 PM

Hmmm.. Still can't figure it out.
the System.Net.HttpWebRequest class looks like it just handles receiveing URL's. what I need is sending URL's with an Authorization CODE in the header of the sent URL.

I'll post again if I find the answer, if there is any other ideas out there don't be shy to post it here.. he he he.

Thanks for the tip Peter.. I saw some other classes in the same visinety as this one.. maybe, maybe...

------------------------
All help is Good help!
Regards
Michael

planoie December 4th, 2003 10:50 AM

The point of that class is to allow you to construct an HTTP request. You should be able to add headers, set the method, the URI, and then launch the request. Isn't that what you want to do?

After you set up the object, you call its "GetResponse" method which actually makes the HTTP request and delivers the result.

Peter
------------------------------------------------------
Work smarter, not harder.

MichaelTJ December 4th, 2003 06:13 PM

I found it at last. Thanks for the follow up Peter, alwasy enspire me to look deeper with that signature of your's..

Here is the workin code for my problem (AT LAST, yuuhuuu)


*********Working Code****************
    Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
        Dim myWebClient As New System.Net.WebClient
        Dim text As String = bt4txt.Text
        text = SQL.URLEncode(text)
        Dim mob As String = SQL.URLEncode(bt4mob.Text)
        'CODE is Pre encoded username/password for Authorization
        Dim CODE As String = "DFGdfGSDFgtgGREGGFhdfFB45ygrFG"
        myWebClient.Headers.Add("Authorization", "Basic " & CODE)
        Dim responseArray As Byte()
'SQL.SMSID is an unique identifier
        responseArray = myWebClient.DownloadData("http://www.mysmsgateway.com:60000/sms?ID=" & SQL.SMSID & "&From=1900&To=%2b" & mob & "&Encoding=ISO-8859-1&Type=text&Data=" & text & "&Price=1")
        Dim response1 As String
        response1 = System.Text.Encoding.ASCII.GetString(responseArray )
        Response.Write("<br>")
        Response.Write(responseArray)
        Response.Write("<br>")
        Response.Write(response1)
    End Sub
**********************END CODE**********************
I can post my SMSID, encoder, decoder if anybody is interrested

------------------------
All help is Good help!
Regards
Michael

BEYTIA December 18th, 2003 03:02 PM

How would you send a XML message to a URL and wait for an XML response?

I have the following URL address "Http://XMLShippingTest.dhl-usa.com/XMLShippingServlet" I have to send it an xml document(xml message) and read the response. Any ideas?


planoie December 18th, 2003 04:29 PM

If this is a SOAP compliant service, you can use .net built in SOAP services to call and retrieve data from it. Usually, you need to build the .net stub class(es) from a WSDL provided by the service. I downloaded the toolkit found at the root of that URL you provided, but didn't see one in there.

Peter
------------------------------------------------------
Work smarter, not harder.

PiyushMathur1981 July 21st, 2005 10:01 AM

Hi Michael,
We are facing the same issue which you have mentioned in your post.
Actually we want to authenticate user from our ASP.Net code to open a url (which is a combination of file name and parameters on a remote server).
We tried the code posted by you but are still facing issues while encoding/decoding the user name:password.
If you could send me the code which you are using for this purpose it would be of great help.

thanks in advance,
Piyush Mathur



All times are GMT -4. The time now is 05:06 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.