Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android、Xamarin、Rest—如何在请求中传递对象_Android_Spring_Rest_Xamarin - Fatal编程技术网

Android、Xamarin、Rest—如何在请求中传递对象

Android、Xamarin、Rest—如何在请求中传递对象,android,spring,rest,xamarin,Android,Spring,Rest,Xamarin,我有一个运行Spring的简单服务器rest端点- @RestController @RequestMapping("/services") @Transactional public class CustomerSignInService { @Autowired private CustomerDAO customerDao; @RequestMapping("/customer/signin") public Customer customerSignI

我有一个运行Spring的简单服务器rest端点-

@RestController
@RequestMapping("/services")
@Transactional
public class CustomerSignInService {

    @Autowired
    private CustomerDAO customerDao;

    @RequestMapping("/customer/signin")
    public Customer customerSignIn(@RequestParam(value = "customer") Customer customer) {
        //Some Code Here...
        return customer;
    }
}
我正在尝试使用此方法从我的Xamarin Android应用程序传递一个Customer对象-

public JsonValue send(String url, SmartJsonSerializer obj)
{
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
    request.ContentType = "application/json";
    request.Method = "POST";

    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
    {
        streamWriter.Write(obj.toJsonString());
    }

    using (WebResponse response = request.GetResponse())
    {
        using (Stream stream = response.GetResponseStream())
        {
            return JsonObject.Load(stream);
        }
    }
}
但我不断收到错误的请求异常(Http错误400),显然我在服务器端的代码没有被触发

SmartJsonSerializer使用JSON.NET将客户对象序列化为字符串-

using System;
using Newtonsoft.Json;

namespace Shared
{
    public class SmartJsonSerializer
    {        
        public string toJson()
        {
            return JsonConvert.SerializeObject(this);
        }
    }
}
感谢您的帮助,
thnx

通常,如果要将复杂对象发布到这样的api中,您会将其写入请求正文中。你看起来确实是在安卓系统上这么做的


我对Spring不太熟悉,但看起来您希望将
customer
作为url参数-尝试将
@RequestParam
替换为。

通常,如果您向这样的api发布复杂对象,您会将其写入请求体。你看起来确实是在安卓系统上这么做的


我对Spring不太熟悉,但看起来您希望将
customer
作为url参数-尝试将
@RequestParam
替换为。

通常,如果您向这样的api发布复杂对象,您会将其写入请求体。你看起来确实是在安卓系统上这么做的


我对Spring不太熟悉,但看起来您希望将
customer
作为url参数-尝试将
@RequestParam
替换为。

通常,如果您向这样的api发布复杂对象,您会将其写入请求体。你看起来确实是在安卓系统上这么做的


我对Spring不太熟悉,但看起来您希望将
customer
作为url参数-尝试将
@RequestParam
替换为。

我曾与它斗争过一段时间,但很明显,解决方案可能在服务器端找到

如果有用的话,你可以看看这个

@RestController
@RequestMapping("/services")
@Transactional
public class SomeService {

                @RequestMapping(value = "/user/signin", method = RequestMethod.POST)
                @ResponseBody
                public AppUser signIn(@RequestBody AppUser appUser) {
                                appUser.invoke();
                                return appUser;
                }
}

我为此挣扎了一段时间,但显然,解决方案可能在服务器端找到

如果有用的话,你可以看看这个

@RestController
@RequestMapping("/services")
@Transactional
public class SomeService {

                @RequestMapping(value = "/user/signin", method = RequestMethod.POST)
                @ResponseBody
                public AppUser signIn(@RequestBody AppUser appUser) {
                                appUser.invoke();
                                return appUser;
                }
}

我为此挣扎了一段时间,但显然,解决方案可能在服务器端找到

如果有用的话,你可以看看这个

@RestController
@RequestMapping("/services")
@Transactional
public class SomeService {

                @RequestMapping(value = "/user/signin", method = RequestMethod.POST)
                @ResponseBody
                public AppUser signIn(@RequestBody AppUser appUser) {
                                appUser.invoke();
                                return appUser;
                }
}

我为此挣扎了一段时间,但显然,解决方案可能在服务器端找到

如果有用的话,你可以看看这个

@RestController
@RequestMapping("/services")
@Transactional
public class SomeService {

                @RequestMapping(value = "/user/signin", method = RequestMethod.POST)
                @ResponseBody
                public AppUser signIn(@RequestBody AppUser appUser) {
                                appUser.invoke();
                                return appUser;
                }
}

@你的身体做了这个把戏!我可以玩我的junit,直到我弄明白-谢谢@你的身体做了这个把戏!我可以玩我的junit,直到我弄明白-谢谢@你的身体做了这个把戏!我可以玩我的junit,直到我弄明白-谢谢@你的身体做了这个把戏!我可以玩我的junit,直到我弄明白-谢谢!!