why do we need addRequestHeader method? - objective-c

Can anyone explain me the role of addRequestHeader method of ASIHTTPRequest class? Why do we need it?
P.S. Browsing over google and stackoverflow i see lots of people familiar with details of ASIHTTPrequest library. Where do you take the information?

Without any knowledge about that class, but most likely the method is used to send a custom header.
For example, when accessing a web service that is usually only hit through XHRs from JavaScript, it might require you to add a X-Requested-With: XMLHttpRequest header.

The info is from ASIHTTPRequest documentation
You need the method to specify header of request.
List of HTTP header fields

Related

How to use OAuth 1.0 in Visual Basic?

I'm trying to make a bot for Tumblr or Twitter, but both require OAuth requests. I'm not sure how to use a Net.WebRquest this way. I've searched all over and found very scarce information. I believe I am supposed to add some credentials in the header. This is what I have tried:
<pre>
Dim request As WebRequest = WebRequest.Create(URL)
request.Headers.Add(HttpRequestHeader.Authorization,
$"OAuth realm=""https://api.tumblr.com/"",
oauth_consumer_key=""{APIKEY}"",
oauth_token=""{TOKEN}"",
oauth_signature_method=""HMAC-SHA1"",
oauth_signature=""?"",
oauth_timestamp=""{(Now - New DateTime(1970, 1, 1)).TotalSeconds}"",
oauth_nonce=""{Now.GetHashCode()}"",
oauth_version=""1.0""")
<pre>
Assuming APIKEY and TOKEN are valid, I am still getting Error 401: Unauthorized. Also, what do I put in "oauth_signature"? That did not make any sense to me. This website contained the most useful information: https://oauth.net/core/1.0a/
Has anyone else here dealt with OAuth requests before, that can help me? If there were any examples out there, that would be wonderful. Thank you so much in advance.
~Nic
What jumps out at me immediately is that your parameters are not sorted alphabetically (which OAUTH requires).
Writing an OAUTH library from scratch is terrible terrible business and you should use an existing library unless you have a really good reason not to.
I am the author of TwitterVB, a .NET library for accessing the Twitter API. The code is hosted on GitHub and has a very permissive license. You'll find code can classes there that will make your implementation of OAUTH much easier.
Please note that I no longer maintain this library and there are a few things that have changed about the API that interfere with its functionality. The OAUTH pieces should all work as-is, however.

can not set restricted headers e.g. UserAgent in WebRequest for PCL

microsoft did not implement it, and will not do so according to this:
https://connect.microsoft.com/VisualStudio/feedback/details/770104/cannot-set-useragent-of-a-httpwebrequest-in-portable-class-and-winrt-libraries
But the web site I'm trying to get response from requires User-Agent header specified in the request, otherwise the response is wrong.
I am limited to using portable class library (PCL), since I'm working on mvvmcross cross platform project.
What is the best way to make such a web request?
As I was trying to point you to in my first comment, Dependency Injection is the best way to go about this. Here is a simple example from the MvvmCross documentation https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control#1-pcl-interface-with-platform-specific-implementation

How to call a URL

In VB.NET how can I call a URL using the POST method?
I am trying to utilize the API of a website but because I have no experience in web services, I don't know how to do this simple code.
If this question confuses you, or I need to add more information please ask!
You're looking for the HttpWebRequest class, or the newer and better HttpClient class.

How to use XMLHttpRequest in Objective-C?

I'm creating easy to use kannada comic reader on mac for my cousins. I'm able to pull the comic pages, but lot of meta content exchanged webpage and server using XMLHttpRequest.
I'm finding difficulties use XMLHttpRequest, could anyone tell me how can I use it?
The closest thing to a simple XMLHttpRequest is to create a data object from a URL.
For more advanced requests (e.g., custom headers, request methods that aren't GET), you'll need to use NSURLConnection. You should probably do that anyway; your application will be more robust and more responsive for it.

Accessing Page From App?

I am only just starting out with iPhone application development and have been doing some research with regards at getting data into an app using information available via the web.
I understand that I can access web pages using the NSURL* classes. Does anyone know how I might request data from a page that requires user input?
I can understand accessing an actual page, but I am not sure if (or how) I might be able to initiate the request and get the appropriate data back into my app.
Any help / pointers is very much appreciated.
EDIT_001:
I was thinking that I would have to interact with the actual controls on the page, but after a little more investigation I have found that I can simply use the request HTML that the page generates.
gary
This question is really too broad ("how does http networking work"), and if you look around this site you will probably find several questions that will take you in the right direction. As a first stop, check out the ASIHTTPRequest framework. Many people use it, and it makes http networking really simple.
You could also have a look at these links for inspiration:
http://iphoneonrails.com/
http://metaskills.net/2010/2/12/synchronizing-core-data-with-rails-3-0-0-pre