我跟着在这篇文章中给出的示例: 如何从MATLAB数据发送到Rails的 ,但我接收我找不到任何信息的错误消息。 我的脚本是这样的:
javaaddpath('./httpcomponents/httpclient-4.2.2.jar')
javaaddpath('./httpcomponents/httpcore-4.2.2.jar')
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
httpclient = DefaultHttpClient();
httppost = HttpPost('http://localhost:3000/signin');
httppost.addHeader('Content-Type','application/json');
httppost.addHeader('Accept','application/json');
tokenRequest = StringEntity('{"session", "{email_address:""email@aol.com,""password:""password""}"}');
httppost.setEntity(tokenRequest);
response = httpclient.execute(httppost);
在最后一行,我得到的错误:
Java的异常:java.lang.VerifyError的:不能从最后一类继承
从在线搜索,据我了解,这是软件版本问题。 我尝试使用4.2建立这些文件(在其他职位所使用的相同的),但我收到了同样的错误。 没有人有一个想法可能是错了吗? 或者知道怎样做我想做而不使用这些外部库做什么?
编辑:
本来我尝试使用此代码:
tokenRequest = {'session', '{''email_address'':''email@aol.com'',''password'':''password''}'};
token = urlread('http://localhost:3000/signin','POST',tokenRequest);
但我收到,导致我的其他职位的NoMethodError:
NoMethodError (undefined method `each' for "{'email_address':'email@aol.com','password':'password'}":String):
app/models/session.rb:14:in `initialize'
我认为它抛出这个错误的原因是因为服务器认为它正在接收String对象,它不具有每种方法。 我想我会用“的Content-Type”参数来指定其JSON解决这个问题。 有没有办法做到这一点使用urlread?
编辑:对Java库问题全堆栈跟踪
Java exception occurred:
java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.mathworks.jmi.CustomURLClassLoader.findClass(ClassLoaderManager.java:760)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)