Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Are there any equivalents in objective-c to the following python urllib2 functions?
Request, urlopen, HTTPError, HTTPCookieProRequest, urlopen, HTTPError, HTTPCookieProcessor
Also, how would I able to to this and change the method from "get" to "post"?
NSMutableHTTPURLRequest, a category of NSMutableURLRequest, is how you set up an HTTP request. Using that class you will specify a method (GET or POST), headers and a url.
NSURLConnection is how you open the connection. You will pass in a request and delegate, and the delegate will receive data, errors and messages related to the connection as they become available.
NSHTTPCookieStorage is how you manage existing cookies. There are a number of related classes in the NSHTTPCookie family.
With urlopen, you open a connection and read from it. There is no direct equivalent to that unless you use something lower level like CFReadStreamCreateForHTTPRequest. In Objective-C everything is passive, where you are notified when events occur on the stream.
You're looking for some combination of NSURL, NSURLRequest, NSURLConnection, NSHTTPConnection, etc. Check out the URL Loading System Programming Guide for all the information you need.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to get the Server header of HTTP with Python. I don't know how can I get it, I looked at the RFC of Hypertext Transfer Protocol and got into the Server section.
The Server response-header field contains information about the
software used by the origin server to handle the request. The field
can contain multiple product tokens (section 3.8) and comments
identifying the server and any significant subproducts. The product
tokens are listed in order of their significance for identifying the
application.
How can we get it ? I can guess that with os or platform, etc.
I am assuming you want to:
Send HTTP requests to a web server and retrieve the 'Server' header
from the HTTP response.
You want to use python.
'requests' is a very popular lib to make HTTP requests (https://requests.readthedocs.io/en/master/)
Here is a code sample very may guide you achieving what you need
import requests
response = requests.get("http://example.com")
print(response.headers['Server'])
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
For example, I tried getting Python to read the following filtered page
http://www.hearthpwn.com/cards?filter-attack-val=1&filter-attack-op=1&display=1
but Python only gets the unfiltered page http://www.hearthpwn.com/cards instead.
The standard library urllib2 normally follows redirects. If retrieving this URL used to work without being redirected, then the site has changed.
Although you can prevent following the redirect within urllib2 (by providing an alternative HTTP handler), I recommend using requests, where you can do:
import requests
r = requests.get('http://www.hearthpwn.com/cards?filter-attack-val=1'
'&filter-attack-op=1&display=1', allow_redirects=False)
print(r)
giving you:
<Response [302]>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am having difficulties with the implementation of the query GET.
For example, I took no difficult task to bring in a convenient form the information on this page GET https://www.bitstamp.net/api/transactions/
Used API https://www.bitstamp.net/api/
I'm interested in everything from syntax to the modules you want to install for this request
Did you already seen this?
http://docs.python-requests.org/en/latest/
e.g:
import requests
response = requests.get(url)
print response.json()
If you don't want to install an extra library, you can use pythons urllib2 library that is just as easy for something like connecting to a url.
import urllib2
print urllib2.urlopen("https://www.bitstamp.net/api/transactions/").read()
For parsing that, use pythons json library.
There is a Python lib for that, the bitstamp-python-client. Do not waste your time reinventing the wheel. ;-)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
If I want to give input to the website through python program and display the result on terminal after online computation then how can I do it using python wrapper? As I am new to python, so Can anyone suggest me some tutorial for this?
It all depends on the website that you want to retrieve your result from, and how it accepts input from you. For example, if your webpage accepts GET or POST requests, then you can send it a HTTP request and print out the response onto terminal.
If your website accepts input via a submit form, on the other hand, you would have to find the link of the submit button and send your data to that page.
There is a Python library called Requests, which you can use to send HTTP requests to a webpage and get the response. I suggest you read its documentation, it has some good examples that you can base your idea off. Another library is the inbuilt urllib2, which would also work for your purposes.
The response to your request is most likely to be a HTTP webpage, so you may have to scrape out your desired content from inside that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Could you please tell me, How do I write a basic webpage without using framework like Django, Web2Py and others third party frameworks. Also, I don't like to use CGI for it. I need basic MVC structure with a hello-world web page only.
I suppose you mean a http server, because for a webpage only, you'd use html, not python.
I suggest you start with some reading on this page. It's the http server for python. As you want to keep things easy, you probably just want to overwrite the BaseHTTPRequestHandler or the SimpleHTTPRequestHandler classes, especially the do_GET and do_POST methods.
Note that this won't force you to use MVC, that's your own responsibility. You'll need an actual framework if you want to enforce MVC.