Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 3rd, 2003, 04:23 PM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
__________________
------------------------
All help is Good help!
Regards
Michael
  #2 (permalink)  
Old December 3rd, 2003, 05:59 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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

Peter
------------------------------------------------------
Work smarter, not harder.
  #3 (permalink)  
Old December 3rd, 2003, 09:39 PM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #4 (permalink)  
Old December 4th, 2003, 10:50 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
  #5 (permalink)  
Old December 4th, 2003, 06:13 PM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #6 (permalink)  
Old December 18th, 2003, 03:02 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

  #7 (permalink)  
Old December 18th, 2003, 04:29 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
  #8 (permalink)  
Old July 21st, 2005, 10:01 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Code - Wrox - Beginning JAVA - Ivor Horton ponguru Java Databases 3 May 18th, 2006 12:30 PM
New.aspx works but login.aspx fails Validation nigelhamilton BOOK: ASP.NET Website Programming Problem-Design-Solution 8 September 13th, 2004 02:29 AM
New.aspx works but not Login.aspx ? reidcor BOOK: ASP.NET Website Programming Problem-Design-Solution 2 May 24th, 2004 10:32 AM
HowTo Pass Form data from Page1.aspx to Page2.aspx dati ASP.NET 1.0 and 1.1 Basics 6 January 27th, 2004 06:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.