Solved How can I get things from website
-
@JKSH
Actually, if i connect success the URl i set will have the record.
But i just check it, there is nothing on it.
I don't know what to do now. -
@JKSH
I solved the problem!
I 'm too stupid that i type the wrong vocabulary.
It's Empid not Empld in the Url.
Thank you so much for all your help! -
@JKSH
There is another questions.manager->get(QNetworkRequest(QUrl(http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&Empid=we9999&CPID=OS&CPKey=95Z0000000AF)));
what if the Empid is not the static one.
It will let the guest type there own id.
If i want to doing that how can i do it?Can i type like this?
manager->get(QNetworkRequest(QUrl("http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&"+"Empid="+ID"&CPID=OS&CPKey=95Z0000000AF")));
-
@victor-wang You can do it like this (Empid= can be just part of the first string - no need for +"Empid=").
Take a look at http://doc.qt.io/qt-5/qstring.html#arg -
@jsulm @JKSH
I've got another question!
I have 10 different Url wanna connect and get information down.
And i'm using for() to do it.Here is my code.But it will crash and will not connect to the server.
I assume that it because for() is doing too quick.
So i add this inside the casereply->isFinished();
But it will crash in the beginning.
What else method can i try or what to fix in my code?
Do i need to add the switch case into replyfinished() slot instead of connect?Please help!
-
@victor-wang The problem isn't that for loop is too fast (how could it be too fast?).
Starting with case one you have:reply->isFinished();
How do you initialize reply? Most probably it is not initialized and you're dereferencing dangling pointer.
Second question: why do you call isFinished() on reply? isFinished() is a getter method which you can use to check whether the reply is finished or not. But you do not use its return value, so the call is completely useless.
In general: if your app is crashing you should first debug it before asking in a forum.
So, please remove that useless reply->isFinished(); and debug your code to see where exactly it is crashing and why. -
@victor-wang
To add to @jsulm :make a make a proper Network function something along the line of:
void getUrlData(QUrl url){ //Do Stuff to call data from one URL }
Place all your QUrls(10?) into a
QList<QUrl>
Now link the
IsFinished
Signal of your reply to Funktion to call the next URL request from your list.Dont forget to add a cancel condition, when you reach the end of your list.
Now, start the download chain by calling the first element of your list by hand/button clicked.
-
@J.Hilk
Is that mean that i have to connect IsFinished signal and getUrlData slot in the replyFinished() slot?
What is that mean put in the QList?
There is no IsFinished () signal for reply, just have finished signal. -
@jsulm
But how can i get 10 times of different Url.
What should i connect signal? -
@victor-wang What do you mean? You do the same: connect finished() signal to your slot. In that slot (which you already have) you can get the URL from the response to know for which URL this response is coming.
QNetworkAccessManager can handle many requests in parallel - no need to do something special. -
@jsulm
https://forum.qt.io/topic/77186/how-can-i-get-10-different-urlThis is my new topic and i had describe it.
I will describe here for you again.
Please help.i will send this commend for 10 times in the different CPID.
CPID="TOUCH"; URL="http://192.168.100.59/OLMS/TeskCheck.asp?LSN="+LSN+"&Empid="+EMPID+"&CPID="+CPID+"&CPKey=XXX"; manager->get(QNetworkRequest(QUrl(URL)));
But during the process it will return 500 instead of 200 and can't connect to the Url for the few times.
How can i solve this problem? -
@victor-wang HTTP 500 status code means: "500 Internal Server Error".
You should check using a browser whether these URLs are working. -
@jsulm
I'm sure it is worked because if i have just connect that one, it will work correctly.
But if it's in the loop and is not at the first one, sometimes will failed but sometime will success.
So that's why i doubt that because it sending too quick that the server cannot catch it well. -
@victor-wang Then it is an issue with your server - it is either too slow or it cannot handle concurrent requests.
-
@jsulm
Did you see my code that i had just gave you?I'm not quite sure that is the server issue.
I doubt that my code is not really perfect.
Could you help me see the code? -
@victor-wang Your do..while loop is an infinite loop if you get a response != 200
It does not make sense as a reply is either 200 or not: it will not become 200 if it wasn't before by some magic, so remove that loop.
As I said 500 means internal server error. You get a connection but the server fails to do what it is expected to do and sends 500 back.
If you want to slow down your requests you can use QTimer. -
-
@victor-wang What does fail mean? Do you get 500?
-
@victor-wang If you do not want to send all request in parallel you can do it one after another.
-
@jsulm
Yes, it will show 500.how to do that?
Could you teach me?Or can i do 5 times and another 5 times.