Looking for help with HTTP POST
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Looking for help with HTTP POST
Dear all,
after searchig for hours (it's 4:37 a.m. now )), my body-batteries are empty.
In spite of this I hope there is a friendly guy out there who can translate the following HTML-script
<html>
<form enctype="multipart/form-data" action="http://xxx.com/a/b/" method="POST">
<!-- MAX_FILE_SIZE (in Bytes) must be given before input-Field, which loads the (graphic)file -->
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<!-- The name" of the Input-Field has to be "file" because it's the name of the POST-Parameter -->
choose graphic to read: <input name="file" type="file" />
<input type="submit" value="read file" />
</form>
</html>
into a LC POST-message that I can use in my app.
Best regards
Ulrich
P.S.: In the final constellation, the graphic can be out of the filesystem of the desktop-PC or made with the camera of a mobile device.
If this makes a difference in handling, it would be very helpful to get it known.
after searchig for hours (it's 4:37 a.m. now )), my body-batteries are empty.
In spite of this I hope there is a friendly guy out there who can translate the following HTML-script
<html>
<form enctype="multipart/form-data" action="http://xxx.com/a/b/" method="POST">
<!-- MAX_FILE_SIZE (in Bytes) must be given before input-Field, which loads the (graphic)file -->
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<!-- The name" of the Input-Field has to be "file" because it's the name of the POST-Parameter -->
choose graphic to read: <input name="file" type="file" />
<input type="submit" value="read file" />
</form>
</html>
into a LC POST-message that I can use in my app.
Best regards
Ulrich
P.S.: In the final constellation, the graphic can be out of the filesystem of the desktop-PC or made with the camera of a mobile device.
If this makes a difference in handling, it would be very helpful to get it known.
-
- VIP Livecode Opensource Backer
- Posts: 9845
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Looking for help with HTTP POST
Did you see the POST command in the Dictionary?
And the "answer file" command will handle to file picker.
And the "answer file" command will handle to file picker.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Location: Plymouth, UK
- Contact:
Re: Looking for help with HTTP POST
Hi Ulrich
For a very simple example of POSTing files to a server search for "simple POST demo" in the 'Sample Stacks' section of the LiveCode toolbar
For a very simple example of POSTing files to a server search for "simple POST demo" in the 'Sample Stacks' section of the LiveCode toolbar
"...this is not the code you are looking for..."
Re: Looking for help with HTTP POST
Hi,
Can you give me support to transform this query into a LC-POST-command ?
I would be so grateful !!!
Best regards
Ulrich
yes, I have seen this and worked through the lessons as well - but I'm sorry to say that I have not been so lucky to get it transformed the right way.FourthWorld wrote:Did you see the POST command in the Dictionary?
And the "answer file" command will handle to file picker.
Can you give me support to transform this query into a LC-POST-command ?
I would be so grateful !!!
Best regards
Ulrich
Re: Looking for help with HTTP POST
Hi Kilroy,
thank you very much vor your tip.
Would it be possible for you to help me getting the right transformation ?
This would be great !!
Best regards
Ulrich
thank you very much vor your tip.
I downloaded this example immediately and tried to find the correct solution for my problem - unfortunately without success...dave.kilroy wrote:Hi Ulrich
For a very simple example of POSTing files to a server search for "simple POST demo" in the 'Sample Stacks' section of the LiveCode toolbar
Would it be possible for you to help me getting the right transformation ?
This would be great !!
Best regards
Ulrich
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Location: Plymouth, UK
- Contact:
Re: Looking for help with HTTP POST
Hi Ulrich
It should work - I'm about to DM you the URL to use to test it on my shared server account (please don't post anything too enormous or malicious). Once you've confirmed it works on my server try getting it working with your own URL (remember, the script of the .lc file needed is in the comments of the stack scrip of my demo post stack)
Kind regards
Dave
It should work - I'm about to DM you the URL to use to test it on my shared server account (please don't post anything too enormous or malicious). Once you've confirmed it works on my server try getting it working with your own URL (remember, the script of the .lc file needed is in the comments of the stack scrip of my demo post stack)
Kind regards
Dave
"...this is not the code you are looking for..."
Re: Looking for help with HTTP POST
Try this code:
and this:
Code: Select all
post "hello world" to URL "http://posttestserver.com/post.php"
launch URL (word -1 of line 2 of it)
Code: Select all
post "MyCar=1" to URL "http://posttestserver.com/post.php"
launch URL (word -1 of line 2 of it)
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Looking for help with HTTP POST
Hi MaxV,
many thanks for your both examples, they work perfect.
I just tried to format my html-form in this way, but unfortunately, I find no working format.
Here is the code I tried at last:
put "enctype=""e&"multipart/form-data""e&space&\
"input name=""e&"file""e&\
" type=""e&"file""e&\
" input type=""e&"submit""e&\
" value=""e&urlencode(image_to_send)"e into theParams
post theParams to URL "http://xxx.com/a/b/"
This does not work.
Would it be possible for you to extract the correct parametrization out of my html-form ?
This would be so helpful to me...
Best regards
Ulrich
many thanks for your both examples, they work perfect.
I just tried to format my html-form in this way, but unfortunately, I find no working format.
Here is the code I tried at last:
put "enctype=""e&"multipart/form-data""e&space&\
"input name=""e&"file""e&\
" type=""e&"file""e&\
" input type=""e&"submit""e&\
" value=""e&urlencode(image_to_send)"e into theParams
post theParams to URL "http://xxx.com/a/b/"
This does not work.
Would it be possible for you to extract the correct parametrization out of my html-form ?
This would be so helpful to me...
Best regards
Ulrich
Re: Looking for help with HTTP POST
The easy way:
I think you need this:
########CODE to copy and paste#######
put "name=" & urlencode(tFileName) into theParams
put "&type=" & urlencode(tFileType) after theParams
put "&value=" & urlencode(base64encode(image_to_send)) after theParams
post theParams to URL "http://xxx.com/a/b/"
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-5#####
Note that tFileName, tFileType and image_to_send are variable containing what you want. Please also note that image_to_send must be filled with something like:
On the server image must be base64decoded.
The hard way
If you want to use the multipart type of POST, then use http://livecode.wikia.com/wiki/LibURLMultipartFormData
I think you need this:
########CODE to copy and paste#######
put "name=" & urlencode(tFileName) into theParams
put "&type=" & urlencode(tFileType) after theParams
put "&value=" & urlencode(base64encode(image_to_send)) after theParams
post theParams to URL "http://xxx.com/a/b/"
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-5#####
Note that tFileName, tFileType and image_to_send are variable containing what you want. Please also note that image_to_send must be filled with something like:
Code: Select all
put URL ("binfile:path/to/image/file.jpg) into image_to_send
The hard way
If you want to use the multipart type of POST, then use http://livecode.wikia.com/wiki/LibURLMultipartFormData
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Looking for help with HTTP POST
Hi MaxV,
thanks for the code you sent.
I tried immediately, but I get the result that the message format is wrong (HTTP Code 400)
For the image_to_send, I took
put URL ("binfile:"&Pfad) into image_to_send (where Pfad is the local file path on my desktop)
What do you think has to be placed in tFileName and tFileType ? I (successless) tried:
+ file file
+ file png
Perhaps it is easier to analyze if you have the concrete szenario. Here it is
<html>
<form enctype="multipart/form-data" action="http://api.qrserver.com/v1/read-qr-code/" method="POST">
<!-- MAX_FILE_SIZE (maximale Dateigröße in Bytes) muss vor dem input-Feld
angegeben werden, über welches die QR Code Grafik hochgeladen wird -->
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<!-- Der "name" des Input-Felds muss "file" lauten, da es sich dabei um den
Namen des POST-Parameters handelt -->
Zu lesende / scannende QR Code-Grafik auswählen: <input name="file" type="file" />
<input type="submit" value="QR Code lesen" />
</form>
</html>
And here is the API for this service:
http://goqr.me/de/api/doc/read-qr-code/
Attached you find the image_to_send:
I hope you can help to find a solution.
Best Regards and many thanks for your further help in advance
Ulrich
thanks for the code you sent.
I tried immediately, but I get the result that the message format is wrong (HTTP Code 400)
For the image_to_send, I took
put URL ("binfile:"&Pfad) into image_to_send (where Pfad is the local file path on my desktop)
What do you think has to be placed in tFileName and tFileType ? I (successless) tried:
+ file file
+ file png
Perhaps it is easier to analyze if you have the concrete szenario. Here it is
<html>
<form enctype="multipart/form-data" action="http://api.qrserver.com/v1/read-qr-code/" method="POST">
<!-- MAX_FILE_SIZE (maximale Dateigröße in Bytes) muss vor dem input-Feld
angegeben werden, über welches die QR Code Grafik hochgeladen wird -->
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<!-- Der "name" des Input-Felds muss "file" lauten, da es sich dabei um den
Namen des POST-Parameters handelt -->
Zu lesende / scannende QR Code-Grafik auswählen: <input name="file" type="file" />
<input type="submit" value="QR Code lesen" />
</form>
</html>
And here is the API for this service:
http://goqr.me/de/api/doc/read-qr-code/
Attached you find the image_to_send:
I hope you can help to find a solution.
Best Regards and many thanks for your further help in advance
Ulrich
MaxV wrote:The easy way:
I think you need this:
########CODE to copy and paste#######
put "name=" & urlencode(tFileName) into theParams
put "&type=" & urlencode(tFileType) after theParams
put "&value=" & urlencode(base64encode(image_to_send)) after theParams
post theParams to URL "http://xxx.com/a/b/"
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-5#####
Note that tFileName, tFileType and image_to_send are variable containing what you want. Please also note that image_to_send must be filled with something like:On the server image must be base64decoded.Code: Select all
put URL ("binfile:path/to/image/file.jpg) into image_to_send
The hard way
If you want to use the multipart type of POST, then use http://livecode.wikia.com/wiki/LibURLMultipartFormData
- Attachments
-
- QR-Code.png (4.66 KiB) Viewed 14177 times
Re: Looking for help with HTTP POST
Hi Dave,
some more explanations to the problem:
There is a free webservice which I want to use for decoding qr-codes
This webservice provides a POST-API which is described in the given HTML-Form (details are given in my last post in this forum)
So I see no other way to use this service than "simulating" the HTML-form.
I found some hints to do so in the web as well.
If there is a better way, I'm absolute grateful for it.
I hope, you can help me to bring this case to a solution.
Best regards
Ulrich
some more explanations to the problem:
There is a free webservice which I want to use for decoding qr-codes
This webservice provides a POST-API which is described in the given HTML-Form (details are given in my last post in this forum)
So I see no other way to use this service than "simulating" the HTML-form.
I found some hints to do so in the web as well.
If there is a better way, I'm absolute grateful for it.
I hope, you can help me to bring this case to a solution.
Best regards
Ulrich
Re: Looking for help with HTTP POST
Now I see.
Well, you have to use the http://livecode.wikia.com/wiki/LibURLMultipartFormData
It works. I got: "sQuiRt library for LiveCode demonstration". Is it right?
This is the code:
########CODE to copy and paste#######
on mouseUp
put empty into tForm
put "http://api.qrserver.com/v1/read-qr-code/" into tUrl
put the filename of image 1 into tFile
put "<file>" & tFile into tFile
if libURLMultipartFormData(tForm, "nam","file","type","file", "file", tFile) is not empty then
answer it ##error
else
set the httpHeaders to line 1 of tForm
post line 2 to -1 of tForm to url tUrl
put it into field 1
## check the result, etc., here
set the httpHeaders to empty
end if
end mouseUp
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
And I attached a working example.
Well, you have to use the http://livecode.wikia.com/wiki/LibURLMultipartFormData
It works. I got: "sQuiRt library for LiveCode demonstration". Is it right?
This is the code:
########CODE to copy and paste#######
on mouseUp
put empty into tForm
put "http://api.qrserver.com/v1/read-qr-code/" into tUrl
put the filename of image 1 into tFile
put "<file>" & tFile into tFile
if libURLMultipartFormData(tForm, "nam","file","type","file", "file", tFile) is not empty then
answer it ##error
else
set the httpHeaders to line 1 of tForm
post line 2 to -1 of tForm to url tUrl
put it into field 1
## check the result, etc., here
set the httpHeaders to empty
end if
end mouseUp
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
And I attached a working example.
- Attachments
-
- QR_Reader.livecode.zip
- (1.18 KiB) Downloaded 318 times
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Looking for help with HTTP POST
MaxV,
thank you so much - you're a hero
I guess that I'd hardly come to this solution which is available now.
Thanks for giving so tremendous support.
I hope I can give sometimes something back...
Best regards
Ulrich
thank you so much - you're a hero
I guess that I'd hardly come to this solution which is available now.
Thanks for giving so tremendous support.
I hope I can give sometimes something back...
Best regards
Ulrich
Re: Looking for help with HTTP POST
Hi MaxV,
solution is perfect for use on desktop, but the function libURLMultipartFormData is not available for mobile platforms.
In spite of this, there is the last step "let it running mobile" to do.
As you can imagine, I have no idea for this as well.
Would you be so kind to have a look after it ?
Best regards
Ulrich
solution is perfect for use on desktop, but the function libURLMultipartFormData is not available for mobile platforms.
In spite of this, there is the last step "let it running mobile" to do.
As you can imagine, I have no idea for this as well.
Would you be so kind to have a look after it ?
Best regards
Ulrich
Re: Looking for help with HTTP POST
Ulrich,
If you're looking to scan QR codes then mergAV and mergXzing will do that without needing to call a remote API.
mergAV is faster.
Here are some threads:
https://www.google.com/url?q=http://lis ... 5t-cmFDoTg
https://www.google.com/url?q=http://lis ... ZXTna4wXeQ
caveat: not all OS platforms are supported.
Jim Lambert
If you're looking to scan QR codes then mergAV and mergXzing will do that without needing to call a remote API.
mergAV is faster.
Here are some threads:
https://www.google.com/url?q=http://lis ... 5t-cmFDoTg
https://www.google.com/url?q=http://lis ... ZXTna4wXeQ
caveat: not all OS platforms are supported.
Jim Lambert