Python 2.4 で HTTP ポスト リクエストを送信しようとしています。投稿リクエストをwiresharkで分析したところ、リクエストのデータには"options=user:john"ではなく"options=user:jo"のみが含まれていました。python が最後の 2 文字を切り捨てる理由を教えてください。これは、短いストリングでも長いストリングでも発生します。これらのライブラリと Python 2.4 を使用する必要があります。
返信ありがとう
私のスクリプト:
import base64
import httplib
data_string = urllib.urlencode({'options':'user:john'})
authheader = 'Basic ' + base64.encodestring("restuser:restbpm")
headers = {"Content-type": "application/x-www-form-urlencoded", "Authorization": authheader}
h = httplib.HTTPConnection('localhost:8080')
h.request('POST', '/bonita-server-rest/API/runtimeAPI/instantiateProcess/Leitungsauskunft--1.9', data_string, headers)
r = h.getresponse()
print r.read()
ワイヤーシャークからの抜粋
TCP
TCP segment data (17 bytes) ..options=user:jo
TCP segment data (2 bytes) hn
HTTP
Line-based text data: application/x-www-form-urlencoded
\r\n
options=user:jo
サーバーログからの抜粋
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: header=authorization=Basic cmVzdHVzZXI6cmVzdGJwbQ==
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: locale=de_DE
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: method=POST
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: parameter=
options=user:jo
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: pathInfo=/API/runtimeAPI/instantiateProcess/Leitungsauskunft--1.9
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: protocol=HTTP/1.1
Mai 07, 2013 4:29:41 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: queryString=null
Python スクリプトからのエラー
<java.lang.IllegalArgumentException>
<detailMessage>The options are null or not well set.</detailMessage>
<stackTrace>
<trace>org.ow2.bonita.facade.impl.AbstractRemoteRuntimeAPIImpl.getAPI(AbstractRemoteRuntimeAPIImpl.java:62)</trace>
<trace>org.ow2.bonita.facade.impl.AbstractRemoteRuntimeAPIImpl.instantiateProcess(AbstractRemoteRuntimeAPIImpl.java:178)</trace>
<trace>sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)</trace>
<trace>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</trace>
<trace>java.lang.reflect.Method.invoke(Method.java:601)</trace>
<trace>org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:124)</trace>
<trace>org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:247)</trace>
<trace>org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:212)</trace>
<trace>org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:202)</trace>
<trace>org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:441)</trace>
<trace>org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:418)</trace>
<trace>org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:111)</trace>
<trace>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:217)</trace>
<trace>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:159)</trace>
<trace>javax.servlet.http.HttpServlet.service(HttpServlet.java:717)</trace>
<trace>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)</trace>
<trace>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)</trace>
<trace>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)</trace>
<trace>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)</trace>
<trace>org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)</trace>
<trace>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)</trace>
<trace>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)</trace>
<trace>org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)</trace>
<trace>org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)</trace>
<trace>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)</trace>
<trace>org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java:156)</trace>
<trace>org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)</trace>
<trace>org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)</trace>
<trace>org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)</trace>
<trace>org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)</trace>
<trace>java.lang.Thread.run(Thread.java:722)</trace>
</stackTrace>
<suppressedExceptions class="java.util.Collections$UnmodifiableRandomAccessList" resolves-to="java.util.Collections$UnmodifiableList">
<c class="list"/>
<list reference="../c"/>
</suppressedExceptions>
Content Length をヘッダーに追加した後のサーバー ログ
Mai 08, 2013 2:03:19 PM org.apache.catalina.valves.RequestDumperValve invoke
INFO: parameter=
options=user:john
Python と urllib2 コード
import urllib2
import urllib
import base64
import sys
url = "http://localhost:8080/bonita-server-rest/API/runtimeAPI/instantiateProcess/Leitungsauskunft--1.9"
data_string = urllib.urlencode({'options':'user:john'})
request_object = urllib2.Request(url, data_string)
authheader = 'Basic ' + base64.encodestring("restuser:restbpm")
request_object.add_header('Authorization', authheader)
request_object.add_header('Content-Type','application/x-www-form-urlencoded')
request_object.add_header('Content-length','21')
try: response = urllib2.urlopen(request_object).read()
except IOError, e:
print e.code
print e.headers