Avatar of pvg1975
pvg1975Flag for Argentina

asked on 

Problem with WebRequest

Hello guys,

Im using the following code, which seems to work fine:

URL = "https://api2.xxxxxxxxxxx.com/user?k=xxxxxxxxxxxxxxxxxxxxxx"
Dim Request2 As HttpWebRequest = WebRequest.Create(URL)
body = "{""external_guid"": """ & Session("userid") & """, ""client_guid"": ""ATR-3dfg43dj56cb7b"", ""email"":""" & Email & """}"
Request2.Method = "POST"
Request2.ContentType = "application/json"
Dim writer As New StreamWriter(Request2.GetRequestStream(), System.Text.Encoding.ASCII)
writer.Write(body)
writer.Close()

The problem is that I have to see the response from the API.

I tried this:

Dim Response2 As HttpWebResponse = Request2.GetResponse

but it returns server 500 error

Any suggestions?

Thanks!
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Jini Jose
Avatar of Jini Jose
Jini Jose
Flag of India image

try this
string strRequest = "login=" + txtMember.Text;
                string url = "";
                url = "http://yoururl?";
                
                StreamWriter myWriter = null;
                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url + strRequest);
                objRequest.Method = "POST";
                objRequest.ContentLength = strRequest.Length;
                objRequest.ContentType = "application/x-www-form-urlencoded";
                myWriter = new StreamWriter(objRequest.GetRequestStream());
                myWriter.Write(strRequest);
                myWriter.Close();
                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    //Result_FromSMS = sr.ReadToEnd();
                    lblMemberStatus.Text = sr.ReadToEnd();
                    if (lblMemberStatus.Text == "true")
                    {
                        lblMemberStatus.Text = "Valid Member";
                        lblMemberStatus.ForeColor = Color.GreenYellow;
                    }
                    else
                    {
                        lblMemberStatus.Text = "Invalid Member";
                        lblMemberStatus.ForeColor = Color.Red;
                    }
                    sr.Close();
                }

Open in new window

Avatar of pvg1975
pvg1975
Flag of Argentina image

ASKER

Ouch, Im doing this in VB, not C#
ASKER CERTIFIED SOLUTION
Avatar of Jini Jose
Jini Jose
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo