我遵循了这篇文章中给出的示例:如何将数据从 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 libs 问题的完整堆栈跟踪
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)