What is basic difference between UploadData and DownloadString in asp.net webclient? - asp.net

I am new to webclient.
I have seen some examples to POST data to a server. I am worrying which one to be used over other. Can any one please tell me what to use when?
UploadData:
system.net.webclient.uploaddata(uri, byte[]);
DownloadString:
WebClient client = new WebClient();
var result = client.DownloadString(someurl);
Suggestions welcome..!

the basic difference between both - Uploaddata method can be used to retrieve data based on provided inputs from specified URI(address of service) while DownloadString can be used to retrieve data without sending any inputs parameters.

Related

Accessing OpenWeather data elements

I am building a simple Visual Basic program, for personal use only, that shows some basic weather forecast information. I did some looking around and decided that OpenWeather is my best option for getting the data.
I wrote a simple program, using the NewtonSoft JSON framework, which includes:
Dim myWeatherData As HttpClient
response = Await myWeatherData.GetAsync(useUrl)
responseBody = Await response.Content.ReadAsStringAsync()
myJSON = JObject.Parse(responseBody)
This code fine as I was able to see the JSON data using JsonConvert.SerializeObject. My question is simply this: Using the above code, would you please show me how to get inside of myJSON to access, for example, the predicted temperature two days from now? Thanks.

Passing Parameters to a post httpweb request in asp.net for vb net code

Hi guys actually I am new to asp.net and had a task to do. I wast to call a api in post method with certain input paramater and in return I get gst address details. The input is as follows:
This is the purpose of this api:
This Service returns GST details (Address,OwnerName,Pincode,etc.)
**Link**=www.mylink.net/gstdata/gst
**method**= post
**input parameters**=> modid,key,gst (All are string types)
I provide gst no and in return gets the address.
Service Output parameters:
**Parameters Possible Values**
**code** 200,400,500
**status** FAILURE/SUCCESS
**error** string
**data** 1.values (map - key=column_name ,value=column_value)
**uniq_id** string
How do I get these values using HttpWebRequest parameter in vb net code? Please help
I would use
Dim WC as new WebClient
Dim HTML as string = WC.downloadstring("http://example.com/GetAdres?of=John")
Now you will have the Actual HTML of your service output. to further process it, we will need a little more information.
It is not clear to me how the service output is actually formatted, for this we need an example in raw HTML. can you please PASTE the actual Source code of the WebPage to me? the real source in source code, do not copy the document itself.
Security note
do not send the pincode... keep it on the server, and send the pincode to the server instead when it needs to be compared.

How can i make a ajax call into aweber to getting a subscriber a list from codebehind in asp.net?

I want to get a subscriber email list from a web site so how can i get through ajax call from code behind?
WebClient client = new WebClient();
WebRequest req = WebRequest.Create("https://api.aweber.com/1.0/accounts/1/lists/xxxxxx/");
req.ContentType = "application/json";
WebResponse response = req.GetResponse();
Above "xxxxx" means a listname.but its give me a bad request error so how can i make a request from code behind in asp.net c#?
The URL is the most likely cause of your problem. AWeber resources are addressed by numeric IDs, not by name. So for your "xxxxx", you would need the list ID rather than the list name as you indicated.
The list IDs together with the list names are visible right in the "lists" collection JSON when you retrieve:
https://api.aweber.com/1.0/accounts/<ACCOUNT ID>/lists/
Another thing I noticed is that your URL has the account ID set to 1. I suspect that's not an accurate account ID in your case.
To accomplish your goal of retrieving the email addresses, finally, you'll want to add "subscribers" to the end of your URL in order to hit the appropriate resource. While a "list" resource contains data specific to the list in question, the subscriber data is a whole additional level of detail.
Example URL:
https://api.aweber.com/1.0/accounts/<ACCOUNT ID>/lists/<LIST ID>/subscribers
If you are still getting exceptions after making those changes, drop AWeber API Support (api#aweber.com) a note with the specifics.

How to send PUT HTTP Request in Flex

I want to send HTTP PUT Request on one URL to update that content of XML via using API.
URL is like this: https://domainname.com/someurls/id.xml
I want to update that content.
But When I am sending this PUT request, I have seen that in Network Monitor of Flex 4, Its going as the POST request on this web, while I am setting method as PUT in HTTPService variable.
So I am getting error.
So is there any way to send the PUT request on the web ?
Or
Is there any special header to set PUT method ?
I have tried method header but its not working....
Please help me.....
I have found the solution to send the put and delete service with HTTPSerivce in flex.
You just have to send one more header with the service method POST.
You have to send data in the POST method and attach one more header X-HTTP-Method-Override and the value as the PUT or DELETE.
Your service will be send as PUT or DELETE.
Thanks......
While Mitul's response did work for me as well, I was able to get PUT and DELETE requests working by doing the following.
var urlLoader:URLLoader = new URLLoader();
var urlString:String = "https://www.google.com/arbitraryUrl.json";
var urlRequest:URLRequest = new URLRequest(urlString);
urlRequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables._method = "DELETE";
urlRequest.data = variables;
urlLoader.load(urlRequest);
So same concept really. Different way of going about it. Hope this helps some people.
Flex doesn't support PUT due to the underlying flash player. See this article about the limitations.
There is a workaround here. However, if both the server and the client are under your control, I'd suggest using only GET and POST. Flex just isn't meant for true RESTful clients. (For example make a post with a parameter put=true)

How do we pass parameters when doing HTTP Post?

I am working on an app where we have to pass specific web api parameters to a web app using HTTP POST.
eg:
apimethod name
parameter1 value
parameter2 value
So do I use a string or URLEncodedPostData to send that data?
It would be good if u help me with a code eg.
I am using something like this but it doesnt post the data to the server.
Though the response code is ok/200 and I also get get a parsed html response when i read the httpresponse input stream. But the code doesnt post anything. So unable to get the expected response.
_postData.append("method", "session.getToken");
_postData.append( "developerKey", "value");
_postData.append( "clientID", "value");
_httpConnection = (HttpConnection) Connector.open(URL, Connector.READ_WRITE);
String encodedData = _postData.toString();
_httpConnection.setRequestMethod(HttpConnection.POST);
_httpConnection.setRequestProperty("User-Agent", "BlackBerry/3.2.1");
_httpConnection.setRequestProperty("Content-Language", "en-US");
_httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
_httpConnection.setRequestProperty("Content-Length",(new Integer(encodedData.length())).toString());
os = _httpConnection.openOutputStream();
os.write(requeststring.getBytes());`
The code you posted above looks correct - although you'll want to do a few more things (maybe you did this already but didn't include it in your code):
Close the outputstream once you've written all the bytes to it
Call getResponseCode() on the connection so that it actually sends the request
POSTed parameters are usually sent in the response BODY, which means URL-encoding them is inappropriate. Quote from the HTTP/1.1 protocol:
Note: The "multipart/form-data" type has been specifically defined
for carrying form data suitable for processing via the POST
request method, as described in RFC 1867 [15].
The post method allows you to use pretty arbitrary message bodies — so it is whatever format the server wants.

Resources