我尝试过多种方式发布HTTP请求(使用PHP和Python)并且我一直收到此错误
string(341) "Can't use an undefined value as an ARRAY reference at /opt/rt4/share/html/REST/1.0/dhandler line 189.
Stack:
[/opt/rt4/share/html/REST/1.0/dhandler:189]
[/opt/rt4/share/html/REST/1.0/autohandler:54]
[/opt/rt4/sbin/../lib/RT/Interface/Web.pm:634]
[/opt/rt4/sbin/../lib/RT/Interface/Web.pm:334]
[/opt/rt4/share/html/autohandler:53]
我试图关注RT REST Guide,但我似乎无法安装他们正在使用的HttpRequest,我无法在线找到它的源代码。
有人有任何建议吗?
这是我的python代码:
import cookielib
import urllib
import urllib2
# creates a cookie for the rtserver with the credentials given at initialization.
# define your credentials here
# here is the RequestTracker URI we try to access
uri = 'http://ip:port/REST/1.0/ticket/1/edit?user=username&pass=password'
# trying login on rt server
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
subdata = {'Subject': 'Test2', "Status":"open"}
data = {'content':subdata}
ldata = urllib.urlencode(data)
login = urllib2.Request(uri, ldata)
print(login.get_full_url())
try:
response = urllib2.urlopen(login)
print response.read()
except urllib2.URLError:
# could not connect to server
print "Not able to login"
这是我的php:
<?php
require('HttpRequest.php');
$username = 'username';
$password = 'password';
//set POST variables
$url = "http://ip:port/REST/1.0/ticket/1/edit?user=$username&pass=$password";
$fields = array("content"=>"Subject=Test2\nStatus=open\n");
$request = new HttpRequest('post', $url, $fields);
print($request->toString());
$request->doRequest();
?>
HttpRequest来自here