Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Remote Server HTTP Requests in .net

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-28 : 07:18:16
Hello,
I have been working with remote server XMLHTTP posts in Classic ASP for years now.

But trying to achieve the same feat in c# .net 3.5.

Am trying to post a query to a linux or unix or windows server. A "SERVERSIDE" post based on a user's request.

e.g. A user wants to see if a domain name exists and submits a form to my domain, which in turn query's icann.org's database remotely and passes a status code back to the user.

here is my code in c#, error message is in red

PROBLEM: Am not sure if this is the right approach to it or not ???


 {
string URL="http://www.1newday.com/login.asp?";
String DataToSend = "LOGIN=" + txtLogin.Text;
String DataPass = "&PASSWORD=" + txtPassword.Text;
String DataItem = "&ITEM_ID=" + txtItem.Text;
String DataZip = "&ZIP_CODE=" + txtZipCode.Text;
String Result= HttpPost(URL,DataToSend);
}
}

public static string HttpPost(string URL, string Parameters)
{
WebRequest req = WebRequest.Create(URL);
// If you are accessing code through proxy server then use below line
//req.Proxy = new System.Net.WebProxy("192.168.0.1", true);
//Add these, as we're doing a POST
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();

WebResponse resp = req.GetResponse();
if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 09:11:16
well i seriously doubt it that anyone here started playing with 3.5.
i know i haven't

maybe you should try asp.net forums.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-01-28 : 09:28:55
3.5!!!

Holy toledo, we're just starting on 2.0 lol...

Corporations stick to the old stuff for a reason!

Most corporations are still running a lot of vb5/6 apps in production and youre on .net 3.5 ???

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-28 : 09:46:14
Maybe telling us what the actual error message is will be helpful? Also, from the code you are showing us, it does not appear that you are sending all of the postdata that you are preparing.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-28 : 14:33:35
Very funny guys.

3.5 is nothing but an enhancement of 2.0 with more controls and addition (Framework installed on my server is 2.xxx)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-28 : 14:41:20
Again, what error message are you getting on that line?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 14:44:00
and an entirely new communication platform that makes everything in .net 2.0 a bit deprecated

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-28 : 15:11:00
hi Jeff,
Error line is in red above. Cannot write to the variable. I just added the System.Net namespace and the error line has stopped.

Spirit1,
how do you mean ?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 15:39:05
lol.. good error

well... WCF services made web services kind of deprecated.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-28 : 18:32:53
Still looking 4a solution
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-28 : 19:11:57
A solution to what? you said you had an error, and then you added the namespace and now you no longer get the error. What is your question? Be specific! After 1550 posts here, you would think you know how this works by now.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-29 : 03:02:47
quote:
Originally posted by jsmith8858

A solution to what? you said you had an error, and then you added the namespace and now you no longer get the error. What is your question? Be specific! After 1550 posts here, you would think you know how this works by now.

- Jeff
http://weblogs.sqlteam.com/JeffS




Temper ! Temper !! Temper !!!

In my first post, i said i have worked with it successfully in classic ASP.

But in .net i said

quote:
Originally posted by afrika


here is my code in c#, error message is in red

PROBLEM: Am not sure if this is the right approach to it or not ???

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-29 : 03:22:18
Bottom line, am not getting a feedback (from the RESPONSE Object) based on the HTTP Serverside post, and was hoping if someone had something similar or could correct me on the right approach.

thanks
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-29 : 08:22:50
OK, let's try one more time.

1. What do you mean by not getting feedback? It is timing out? throwing an exception? Resp is always null? The response stream is always empty?

2. Did you read what I wrote in my very first response? Are you aware that in the code you are showing us, you are not sending PASSWORD or ITEMID or ZIPCODE url parameters to your http request?


3. Are you sure that where you are trying to retrieve data that you are using the right credentials, passing the right URL data, that it is configured and working properly and set to return what you are expecting? Have you step through your code line by line to see how each statement is performing to ensure that it all is working?

4. Have you tried something simple like getting the HTML returned from http://www.google.com or something like that? Never try to pass post data and all that and do anything complicated unless you can do simple stuff first.

5. Finally, even knowing nothing about your http://www.1newday.com/login.asp website, if you go there, right away it redirects to loginX.asp. Is that the URL you are supposed to be using? Are there other form fields or post data that you need to send? There appears to be a bunch of hidden INPUTs on that page -- do you need to pass/send those values as well in your post data?

You ARE taking the right approach technically, this is how you do it, but if are not clear about what you expect to happen and specifically what IS happening instead, and if you aren't showing us actual code with actual error messages and all, there is no way anyone can help you. And you should always start simple, eliminate the unknowns as much as possible when trying a new technique, such as using a simple "default.htm" that returns "hello world!" or trying a simple site that requires no logon or postdata like google.com, and slowly add more to your code and do more as each step is proven to work.


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-01-29 : 09:07:02
For some reason that site just reminds me of the nigerian scam email that I get every once in a while

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-29 : 09:29:49
Jon,
not a fair statement to say. I live, schooled and work in the UK and have been on this site sqlteam.com for years. Also travelled the world. Nigeria is home for me and wont deny my roots, irrespective.

but hey ! lets drop the topic
ta
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-29 : 09:30:15
@afrika:
jeff or jon?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-29 : 09:36:53
@Spirit1 lol,
made a mistake, but corrected it.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-29 : 10:12:23
Did you even see my response? I took quite a bit of time to try to help you out.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-29 : 10:49:11
yes, Jeff. I saw it and do appreciate it.

Actually, am testing it with the above domain to see if i can query the page successfully and removed the "ACTUAL" REMOTE GATEWAY url for security reasons AND also tried to scale down and edit the code, as much as possible.

The remote gateway is really different from above and has many other parameters appended to it. IN all test URL's the resp variable is always empty for now. I will try and query google with it as suggested.

After putting the namespaces, i dont get any error message and the return value is empty also. So Am testing with different websites to see if i can actually get a server-side feedback.

I also posted on asp.net forums, no answers yet
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-01-29 : 13:30:58
quote:
Originally posted by afrika

Jon,
not a fair statement to say. I live, schooled and work in the UK and have been on this site sqlteam.com for years. Also travelled the world. Nigeria is home for me and wont deny my roots, irrespective.

but hey ! lets drop the topic
ta



I wasn't trying to be mean...the site just looked kind of hoaxish that was all. Its the design element that I was critiquing..maybe the thing can do circles around me based on its functionality but the design just was cheesy thats all. I don't mean to offend you or the country of nigeria :). Just trying to give you some feedback..plus the site has a lot of bank information and has the word "money" in a lot of different areas. It gave it a misleading apperance that was all.

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
    Next Page

- Advertisement -