我想通过Spring api从我的Android客户端向我的Restful Spring网络服务发送数据,但我得到了以下的解释,任何人都可以帮助我吗? 例如,我想将用户注册到我的服务器,在我的服务器端我有这样的注册方法:
@RequestMapping(value = "/register")
public boolean registerNewUser(@RequestParam(name = "user")User user){
if(user!=null){
try {
SessionFactory sessionFactory=HibenateConnection.connectingHibernate();
Session session=sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
return true;
}catch (Exception e){
e.printStackTrace();
}
}
return false;
}
在我的客户端,我在Asynctask类中打开连接,如下所示:
@Override
protected ResponseHandler doInBackground(Object... params) {
try {
serverResponse=new ServerResponse();
result = restTemplate.getForObject(URL+conditions,tClass,params);
serverResponse.singleResult=result;
serverResponse.isReady=true;
responseHandler.onServerRespond(serverResponse);
}catch (Exception e){
serverResponse.isReady=false;
serverResponse.message=e.getMessage();
}
return responseHandler;
}
我用我的用户在我的Activity上调用了这个方法:
public static void registerUser(User user,ResponseHandler responseHandler){
String condition="/user_api/register?user=";
new Core<Long>(condition,Long.class,responseHandler).execute(user);
}
我在我的Core AsynTask类的第restTemplate.getForObject(URL+conditions,tClass,params);
行获得了Exeption,其例外是:
Could not create URI object: Illegal character in scheme at index 0: 192.168.1.2:/3000/user_api/register?user
我的服务器网址是192.168.1.2:3000
答案 0 :(得分:1)
答案很简单,但通常很难调试,因为很容易忘记在本地网址SELECT
quote.id ,
quote.createdAt,
max(status.status) AS 'Status'
FROM
quote
JOIN
quotelog ON quotelog.quote = quote.id
JOIN
status ON status.id = quotelog.status
GROUP BY quote.id
之前添加协议部分http://
。因此,在您的情况下,最终网址应如下所示:
192.168.1.2