Az önce oluşturduğum sunucu uygulamasını denemek için bir birim sınaması oluşturuyorum. Kaçırdığım bir şeyNameValuePairs Listesinden bir UrlEncodedFormEntity Oluşturma bir NullPointerException atar
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
var mı:
@Test
public void test() throws ParseException, IOException {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:8080/WebService/MakeBaby");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("father_name", "Foo"));
nameValuePairs.add(new BasicNameValuePair("mother_name", "Bar"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = null;
try {
response = client.execute(post);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String stringifiedResponse = EntityUtils.toString(response.getEntity());
System.out.println(stringifiedResponse);
assertNotNull(stringifiedResponse);
}
aşağıdaki satırı bir NullPointerException üretir?
Ben artık cevabı kabul edebiliriz. Aynı istisna vardı ve kodlamayı ekledim. Teşekkür ederim. –
Bence bu 10 gibi aptalca bir soru değil :), benim de problemim sana benzer. Teşekkürler. –
Bu, benim için günü kurtardı: Çiftlerde utf-8 değerleri vardı ve böylece doğru şekilde kodlanmıyorlardı - ISO-8859-1'in yapacağı gibi utf-8 karakterini savunuyordu! Teşekkürler! – rfay