我正在制作一个使用网络服务的机器人应用程序。当我传入一个字符串时,我有它工作,但是当我尝试使用Xstream时它不起作用。我已经从Xstream和我自己打印出xml字符串,它们是相同的。如果没有xstream,它看起来像这样并且可以工作
`HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://softeng.cs.uwosh.edu/students/cs342g6/login.php");
Boolean response = false;
try
{
String test = "<Login>" +
"<password>" + "lernrane" + "</password>" +
"<user_name>" + "jake@jake.com" + "</user_name>" +
"</Login>";
StringEntity se = new StringEntity(test,
HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
System.out.println("MADE IT TO RESPONSE");
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String resp = EntityUtils.toString(resEntity);
System.out.println(resp);
response = convertToBool(resp);`
但是当我使用xstream时,它看起来像这样并且失败
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://softeng.cs.uwosh.edu/students/cs342g6/login.php");
Boolean response = false;
try
{
LoginObject login = new LoginObject();
login.setUserName("jake@jake.com");
login.setPassword("lernrane");
XStream xstream = new XStream();
xstream.alias("Login", LoginObject.class);
String xml = xstream.toXML(login);
System.out.println(xml);
StringEntity se = new StringEntity(xml,
HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
System.out.println("MADE IT TO RESPONSE");
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String resp = EntityUtils.toString(resEntity);
System.out.println(resp);
response = convertToBool(resp);
我的网络服务看起来像这样
$dom = new domDocument;
$dom = simplexml_load_file('php://input');
$xml = simplexml_import_dom($dom);
$user = Users::find_by_user_name($xml->user_name);
if($user)
{
if($user->password == $xml->password)
{
echo "TRUE";
}
}
else
echo "FALSE";
忽略看起来奇怪的查询,我正在使用有效记录,我知道它正常工作...谢谢
答案 0 :(得分:-1)
我想通了......当我打印出我的xml时,user_name看起来像这个user__name,尽管它明确地命名为user_name。必须存在某种类型的字符集冲突,所以我只是在没有下划线的情况下重命名它。