http request problem

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
paulalsmith1000
Posts: 52
Joined: Sat Jun 15, 2019 10:09 am

http request problem

Post by paulalsmith1000 » Sun Mar 01, 2020 1:48 am

Hi There

I've just come back to livecode after a while and something I'd already done doesn't seem to work?

I've formed htto requests before without any problems, but now this happens:-

GET url ("https://www.googleapis.com/youtube/v3/s ... t&q=little simz, offence&key=AIzaSyC-k5IU6jr9eHxL7Zkt-QQEO4pPW4zdIp0") ; put it into theURL

-works fine, but if I try to add in variables

put "https://www.googleapis.com/youtube/v3/s ... snippet&q=" & ttitle & ", " & tartist & "&key=AIzaSyDUT_zKdAsDjXNmUzyiGQU-9ooAewZ3qQE" into theURL

GET url(theURL) ; put it into theURL

-it doesn't work. could anyone suggest why?

kind regards

Paul

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7653
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: http request problem

Post by FourthWorld » Sun Mar 01, 2020 2:20 am

1. Have you verified that ttitle and tartist contain what you expect? Does the resulting URL work in a browser?

2. Is that your actual app API key? If so you might want to change it now that it's been posted in a public forum.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 898
Joined: Fri Aug 15, 2008 7:15 am

Re: http request problem

Post by bangkok » Sun Mar 01, 2020 6:56 am

& ttitle & ", "& tartist & "&key=AIzaSyDUT_zKdAsDjXNmUzyiGQU-9ooAewZ3qQE" into theURL

Watch out....

A space in a URL is a no go....

And it's clear to me that you have a space in your URL ;-)
(after the comma)

paulalsmith1000
Posts: 52
Joined: Sat Jun 15, 2019 10:09 am

Re: http request problem

Post by paulalsmith1000 » Sun Mar 01, 2020 11:45 am

Hi There

I have tested the resulting URL in the browser and it works fine (it returns the json response as expected), so the variables and the key work.

if I 'put' the result with the variable URL, I get this back????

Kind regards

Paul

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelo ... 0x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>400.</b> <ins>That’s an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>That’s all we know.</ins>

bogs
Posts: 4620
Joined: Sat Feb 25, 2017 10:45 pm

Re: http request problem

Post by bogs » Sun Mar 01, 2020 12:16 pm

bangkok wrote:
Sun Mar 01, 2020 6:56 am
A space in a URL is a no go....
paulalsmith1000 wrote:
Sun Mar 01, 2020 11:45 am
I have tested the resulting URL in the browser and it works fine
When you test the URL in a browser, the browser itself inserts a %20 to replace the 'space' in the address,
aPic_urlWithSpacesInBrowser.png
I need less space...s...
aPic_urlWithSpacesInBrowser.png (8.07 KiB) Viewed 633 times
where as Lc does not, you'd have to insert those yourself through code if such are there, hence what bangkok is telling you.
Image

paulalsmith1000
Posts: 52
Joined: Sat Jun 15, 2019 10:09 am

Re: http request problem

Post by paulalsmith1000 » Sun Mar 01, 2020 4:27 pm

Thank you very much for your help.

It turns out I was being a div anyway!

I'd removed the space before, because I thought it might be the problem, but it had no affect.

It's only the last post that made me look back through it (I thought if it worked in the browser, it would work in LC).

stupidly the error is in one of the variables - there is a space between the first and second name of the artist!!!!!!

so I put the 2 together and used urlencode, al good.

thanks v much again

Paul

Post Reply

Return to “Internet”