making WebResponse GetResponse WebBot wait for redirect - webresponse

I am making a bot that simulates a human user using a specific website.
When the user uses the site here is what happens
the user uploads a file by using the site's Browse button and then clicks Upload
the server responds immediately and the user sees a Please Wait gif
in the meantime the server is evaluating the file for errors. When it is done it redirects, and the user is take to a new .aspx page where they can correct the errors.
What I am not able to do w the bot is make it wait to get the redirect info.
The bot hits the website with this line of code (VB.NET)
Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
The Response has the Please Wait gif in it, not the Errors.aspx page. Somehow I need to make the bot, execute that line of code above then, sorta listen to the same port(?) and wait for the web server to send another response.
Ideas?

I ended up just sleeping the thread, then hitting the url again, repeatedly till I got the response I wanted.

Related

Press enter key to receive http request

I have a problem with Flask. My code is running on a server, and it has the purpose of process HTTP request made from an app built with Flutter. It works, but sometimes I have to press the enter key in the command line to process the request: I tried to add “\n” at the end of the URL, and it works for GET requests (I think this was the solution), but for POST it doesn’t work.
This is the method that should execute when a new POST request is received:
#app.route('/proveedores/agregar', methods = ['POST'])
def proveedorAgre():
content = request.json
print(content)
But sometimes the function doesn’t execute unless I press enter key in the cmd
Someone knows what is happening?

Qt GET request strange response

I'm writing a program to log into a game a get some information from the account.
After making a post request with username and password, I make a get request in the same location in order to download the needed html source.
However, doing qDebug()<<QString(reply->readAll());
prints "\u001F?\b" ,instead of the entire source code of the page.
The get reply has status code 200, and the error() function returns NetworkError(NoError).
For the post and get requests I'm using header information obtained from chrome's network tab in developer options combined with cookies obtained from previous response headers.
I'm doing a get request after the log-in post request because that's what seems to happen in the actual webpage, as displayed in developer options.
The response might be gzipped. Does unzipping happen to yield the expected result?

Asynchronous view with client update for long running processes / views

I have one view in my app that can take quite a long time to be served to the client when requested. In order to inform the user that the server is working I want to present the user some kind like a progress bar, but it is not really a progress bar, it s more like this:
a) client is requesting /myapp/longrunningview/
b) server returns part of the html side, including someting animated that looks like the server is working. At the same time server is calculating the rest of the response, the process which takes very long
c) server finished and returns the response to the client
d) at client side the response is presented
It is not really a progress bar, since the user may request this page from a page outside my app, and I want to return instantly something to the user, without the need to wait for the entire process to be finished. The progress bar implementations that I have found are all based upon some form which is send to the server, while the client showing a progress bar, while waiting for the response.
I would use a celery task for this sort of thing. When the user makes the request, start the task and then send back a page with a progress spinner or whatever, then either have a piece of AJAX hit the server every few seconds asking if it's done, or utilize socketio and django-socketio or a similar package to push a "finished" notification to the client, which can then redirect you to wherever you need to go.
Resources:
Django-SocketIO https://github.com/stephenmcd/django-socketio
SocketIO http://socket.io/
Celery http://celeryproject.org/
Django-Celery http://docs.celeryproject.org/en/latest/django/index.html

Connecting a desktop application with a website

I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?

api request returns json files and not html/xml browser content

I am sending get httpwebrequests to the facebook graph api and all was working fine till I deployed to production server and now module that expects html/xml response is not working and when tested url in internet explorer, the save file dialog pops up and the file needs to be saved.
Other modules also send requests to the facebook graph but just differ in the form of requests so not sure what is going on here.
Any ideas appreciated
Edit:
Let me try and rephrase this. On my production server the httpwebrequest was not returning the correct result. So to Test it I copied the url http://graph.facebook.com/pepsi which is an example, should return the profile info viewable in the browser. The server has internet explorer v8 and I am not sure why it tries to download the file instead of displaying it in the browser. this is what is happening in my code and when I make a request to a different part of the api, then it works in my app but not in the browser
Your question is not very clear. From what I gather, you want the display the JSON response in a browser. Instead, you are being asked to download a file by the browser.
Well, this is normal behaviour. The response you get from Facebook would most likely have a MIME type of application/json. Most newer web browsers display the text in the browser itself. Some browsers, however don't know how to handle this content type and just ask you to download the file.
You mentioned that your module expects an html/xml response. Try changing this to application/json.
You also said that it works in your app but not in your browser. I don't know what you're making, but generally you wouldn't show raw json to the user in a browser, right?