Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:51 PM.


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