PHP Web Interactions
I'm having trouble with a PHP API that my company paid to access. We were given the specifications as far as what requests give which response and such, but we have no access to the authentication code. We can access the information by physically typing the requests into a browser, but I am having trouble thinking of a way to do this from a new web site. I know this is a very open question, but as I have little experience in web programming, does anyone have any suggestions?
|
I guess you want to make one HTTP request from a running PHP script (so that you can access a remote API as you are saying).
http://pear.php.net/HTTP_Request2 |
I have tried this with HttpRequest with no results- will it make a difference to try it with HTTP_Request2? Also, is the code I used correct? (As I said, I'm very new to web coding)
Code:
<html> EDIT: I should probably mention that I am fairly certain this code is incorrect, as it appears to be breaking when I create the request, rather than when I send it. |
What API is that? I mean, request class for HTTP/Request2 is HTTP_Request2? Also, so it doesn't work because? do you have logs? What's the possible return value of send()? Will it say if the request failed? If so, where can you get information about the failure reason?
In HTTP_Response2 it's something like: Code:
$req = new HTTP_Request2(); |
I'm not sure why, but that code gives me an 'unexpected T_VARIABLE' error. I have checked it six times, and there are no missing semicolons or unbalanced parens/brackets. I can't find any incorrect syntax at all, but I'm still getting that error.
|
You sure have a syntax error. Can you paste your code here or in a pastebin?
|
Code:
<html> I'm going to feel really stupid when this turns out to be a semicolon that I overlooked six consecutive times... |
I guess it was my fault:
Code:
} catch (Exception $e) { |
I fixed the 'unexpected T_VARIABLE' error with
catch (Exception $e) But then I get another error, the rest of the code would be very useful. |
Probably that the class is unknown? You have to require the HTTP/Request2 library.
|
Yeah, I figured there would be more to do once I got that part working, but I wanted to start with getting it to run. And I probably should have seen that as well- I have been working on getting PHP figured out for a couple days now, but I guess I'm not picking it up very quickly.
|
Take it easy. How do gringos say it? Slowly but surely? That's the motto for development.
|
lol- I appreciate the 'gringo'. And thank you very much- you've helped a lot. One problem down, 999,999 to go.
|
You're welcome, dude.
|
One step at time.
I don't have that pear library so my help is quite limited at the moment. I am still not really sure which is your exact problem, it is easy to help if you are very verbose about what is going on and what your exact problem is. |
You can download the library instead of using pear.
http://download.pear.php.net/package...est2-2.1.1.tgz |
Well Bertlef, this particular problem is solved. The code is sending the request off, and displaying the response properly. My next step is to figure out how to deal with the authentication, which is impossible to work with. Thanks though!
|
eantoranz: thanks, I guess I won't be needing it now :)
Awesome then! I'm glad you where able to sort it out. |
All times are GMT -5. The time now is 02:57 AM. |