LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2012, 04:05 PM   #1
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Rep: Reputation: 15
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?
 
Old 05-23-2012, 04:32 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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
 
1 members found this post helpful.
Old 05-24-2012, 08:56 AM   #3
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Original Poster
Rep: Reputation: 15
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>
<body>
test
<?php

$req = new HttpRequest("<siteURL>", HttpRequest::METH_GET);
$req->send();

echo $req->getResponseBody();

?>
</body>
</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.

Last edited by Tyler_H72; 05-24-2012 at 09:27 AM.
 
Old 05-24-2012, 09:04 AM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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();
$req->setUrl("$whateverurl");
try{
	$response = $req->send(); 
	$responseCode = $response->getStatus();
	if ($responseCode != 200) {
		// whatever
	} else {
		// it's ok
		echo "response content: " . $response->getBody();
	}
} catch ($ex) {
	echo "Exception: $ex";
}
 
1 members found this post helpful.
Old 05-24-2012, 10:25 AM   #5
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Original Poster
Rep: Reputation: 15
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.
 
Old 05-24-2012, 10:29 AM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
You sure have a syntax error. Can you paste your code here or in a pastebin?
 
Old 05-24-2012, 10:35 AM   #7
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Original Poster
Rep: Reputation: 15
Code:
<html>
<body>
test
<?php


echo "test";

$req = new HTTP_Request2();
$req->setUrl("$whateverurl");
try {
	$response = $req->send();
echo "test1";
	$responseCode = $response->getStatus();
echo "test2";
	if ($responseCode != 200) {
echo "test3";
	} else {
		echo "response content: " . $response->getBody();
	}
} catch($ex) {
	echo "Exception: $ex";
}



?>
</body>
</html>



I'm going to feel really stupid when this turns out to be a semicolon that I overlooked six consecutive times...
 
Old 05-24-2012, 10:41 AM   #8
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
I guess it was my fault:

Code:
} catch (Exception $e) {
 
1 members found this post helpful.
Old 05-24-2012, 10:41 AM   #9
bertlef
Member
 
Registered: Dec 2004
Location: Costa Rica
Distribution: Ubuntu
Posts: 69

Rep: Reputation: 17
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.
 
1 members found this post helpful.
Old 05-24-2012, 10:43 AM   #10
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Probably that the class is unknown? You have to require the HTTP/Request2 library.
 
Old 05-24-2012, 10:45 AM   #11
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Original Poster
Rep: Reputation: 15
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.
 
Old 05-24-2012, 10:48 AM   #12
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Take it easy. How do gringos say it? Slowly but surely? That's the motto for development.
 
Old 05-24-2012, 10:53 AM   #13
Tyler_H72
Member
 
Registered: May 2008
Distribution: OpenSuSE
Posts: 65

Original Poster
Rep: Reputation: 15
lol- I appreciate the 'gringo'. And thank you very much- you've helped a lot. One problem down, 999,999 to go.
 
Old 05-24-2012, 10:55 AM   #14
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
You're welcome, dude.
 
Old 05-24-2012, 10:56 AM   #15
bertlef
Member
 
Registered: Dec 2004
Location: Costa Rica
Distribution: Ubuntu
Posts: 69

Rep: Reputation: 17
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OpenOffice.org: Interactions Between Programs LXer Syndicated Linux News 0 09-16-2010 06:20 PM
Udev, rc.S & rc.hotplug interactions SlackwareInAZ Slackware 3 08-17-2006 06:30 PM
Web services in PHP bahadur Programming 4 06-07-2006 07:34 AM
Web authentication with PHP on an AD ninobi Slackware 4 05-10-2006 07:42 AM
GtkAdjustment interactions mvt Programming 0 05-19-2004 12:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration