方法发布json - Angular js

时间:2015-07-15 18:05:35

标签: json angularjs http

我的请求中有问题,服务器等待:

*POST /work/v1/chats/ HTTP/1.1
X-Client-Instance: clienteinstance
Content-Type: multipart/form-data; boundary=32366fff-0f80-474c-a809-14e6ffaacca1
Content-Length: 352
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.0.2; XT1033 Build/LXB22.46-28)
Host: XXXXXX
Connection: Keep-Alive
Accept-Encoding: gzip
--32366fff-0f80-474c-a809-14e6ffaacca1
Content-Disposition: form-data; name="message-body"
Content-Type: application/json; charset=UTF-8
Content-Length: 110
Content-Transfer-Encoding: binary
{"attachment":"","content":"Test","localAddress":"XXXXXX","receiver":"XXXXX"}
--32366fff-0f80-474c-a809-14e6ffaacca1--*
500 Internal Server Error
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/8
Content-Type: text/plain
Content-Length: 71
Date: Wed, 15 Jul 2015 17:15:10 GMT


HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/8
Transfer-Encoding: chunked
Content-Type: application/json
Date: Tue, 14 Jul 2015 13:56:48 GMT

并在我的请求中发送:

POST /work/v1/chats HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0
Accept: application/json, text/plain, */*
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-Client-Instance: client instance
Content-Type: multipart/form-data; charset=UTF-8
Referer: http://localhost:8080/uc/
Content-Length: 120
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

{"data":{"attachment":"","content":"Test","localAddress":"XXXXXX","receiver":"XXXXX"}}HTTP/1.1 500 Internal Server Error
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/8
Content-Type: text/plain
Content-Length: 71
Date: Wed, 15 Jul 2015 17:15:10 GMT

如何添加身体?在我的请求中?

Content-Disposition: form-data; name="message-body"
Content-Type: application/json; charset=UTF-8
Content-Length: 110
Content-Transfer-Encoding: binary
{"attachment":"","content":"Test","localAddress":"XXXXXX","receiver":"XXXXX"}
--32366fff-0f80-474c-a809-14e6ffaacca1--*

代码:

	$scope.sendMsg = function(){

		
	$http.post('http://localhost:8080/work/v1/chats', {data: 
				{attachment:"",
				 content:"Test",
				 localAddress:"192.168.90.244",
				 receiver:"XXX"}}, { headers: {'X-Client-Instance': 'XXXX', 'Content-Type': 'multipart/form-data'}}  )
.success( function(data)
 {
    alert("success!");
 })
 .error( function( data)
 {
   alert("error!");
 });
	
	
};

0 个答案:

没有答案