문제

IT 메소드를 사용하여 TRAC XMLRPCPLUGIN을 사용하여 JSON RPC를 통해 일부 데이터에 액세스하려고합니다. 서버 측의 확장 점과 클라이언트 측의 jQuery Ajax 요청을 사용하십시오. Firefox 포스터 확장을 사용하여 데이터에 액세스 할 수 있지만 JQuery Ajax 요청을 사용하여 오류 메시지가 표시됩니다. 내가 얻는 오류 메시지는 다음과 같습니다.

Trac[web_ui] DEBUG: RPC incoming request of content type 'application/json' dispatched 
to <tracrpc.json_rpc.JsonRpcProtocol object at 0x03CA51F0>
Trac[web_ui] DEBUG: RPC(JSON-RPC) call by 'PaulWilding'
Trac[json_rpc] ERROR: RPC(json) decode error 
Traceback (most recent call last):
  File "build\bdist.win32\egg\tracrpc\json_rpc.py", line 148, in parse_rpc_request
    data = json.load(req, cls=TracRpcJSONDecoder)
  File "C:\Python27\Lib\json\__init__.py", line 278, in load
    **kw)
  File "C:\Python27\Lib\json\__init__.py", line 339, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "build\bdist.win32\egg\tracrpc\json_rpc.py", line 99, in decode
    obj = json.JSONDecoder.decode(self, obj, *args, **kwargs)
  File "C:\Python27\Lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\Lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Trac[web_ui] ERROR: RPC(JSON-RPC) Error
Traceback (most recent call last):
  File "build\bdist.win32\egg\tracrpc\web_ui.py", line 143, in _rpc_process
    rpcreq = req.rpc = protocol.parse_rpc_request(req, content_type)
  File "build\bdist.win32\egg\tracrpc\json_rpc.py", line 162, in parse_rpc_request
    raise JsonProtocolException(e, -32700)
JsonProtocolException: No JSON object could be decoded
Trac[json_rpc] DEBUG: RPC(json) encoded response: {"error": {"message": "JsonProtocolException details : No JSON object could be decoded", "code": -32700, "name": "JSONRPCError"}, "result": null, "id": null}
.

jQuery 요청은 다음과 같습니다.

 url: "http://localhost/Projects/jsonrpc",
   contentType: "application/json",
   dataType: "jsonp",
   data: {"method": "breq.getBreqs"},
   type: 'POST',
   success: function (repsonse) {
          alert("success");
   },
   error: function (jqXHR, textStatus, errorThrown) {
          alert("Error: " + textStatus);
   }      
.

포스터를 통해 일하는 요청은 단순히 응용 프로그램 / JSON으로 설정된 컨텐츠와 URL과 동일한 URL을 사용하여 단순히 "{"메소드 ":"메소드 "}"입니다.

PHP 프록시와 함께 사용하면이 문제에 대한 몇 가지 게시물을 읽고 TRAC RPC 플러그인에서 PARSE_RPC_REQUEST에서 요청을 로깅하려고했지만 작업 및 비 작동 모두에 대해서만 동일한 문자열 만 반환했습니다. 요청.

JavaScript의 요청이 내 컴퓨터에있는 TRAC 테스트 베드의 요청이있는 것처럼 JavaScript의 동일한 원점 정책으로 인해 문제가 발생하지 않습니다. 그러나 플러그인이 메인 네트워크 내부에있는 서버에 배포되면이 문제가되며 그렇다면 어떻게해야합니까?

문제가 동일한 원점 정책으로 수행하지 않으면 누구나 그것을 원인이되는 것을 알고 있습니까?

도움이 되었습니까?

해결책

전화가 URL이 입력을 인코딩합니다. 이는 JSON-RPC에 대해 원하는 것이 아닙니다.요청 본문이 추가 된 문자 나 정보가없는 JSON 문자열이되도록 원합니다.

브라우저 JavaScript 콘솔에서 잘로드되는 스 니펫의 새 버전이 있지만 TRAC RPC 설치를 위해 작동하도록 system.listMethods (사용자 지정 방법)를 호출합니다.

$.ajax({
   url: "http://localhost/trac/rpc",
   contentType: "application/json",
   dataType: "text",
   data: JSON.stringify({method: "system.listMethods", id: 42}),
   type: 'POST',
   success: function (response) {
       incoming = JSON.parse(response)
       alert("Result ID " + incoming["id"] + ": " + incoming["result"]);
   },
   error: function (jqXHR, textStatus, errorThrown) {
       alert("Error: " + textStatus);
   }
});
.

/login/rpcanonymous 권한을 할당하지 않으면 XML_RPC URL을 사용합니다.

다른 팁

문제는 실제로 매개 변수로 보내는 것일 수 있습니다.

data: {"method": "breq.getBreqs"}
.

여기에 설명 된 솔루션을 사용해보십시오. jquery ajax json을 webservice에 게시

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top