代码:
String recipeName = this.recipe.getName().replace(" ", "%20");;
String recipeIngredients = this.recipe.getIngredients().replace(" ", "%20");;
String recipeInstructions = this.recipe.getInstructions().replace(" ", "%20");;
String recipeUserName = this.recipe.getUserName().replace(" ", "%20");;
int recipeRate = this.recipe.getRate();
int recipeAmountOfRate = this.recipe.getAmountOfRates();
String link = "http://***My_Site***/createRecipe.php?recipeName="+recipeName+"&recipeIngredients="+recipeIngredients
+"&recipeInstructions="+recipeInstructions+"&recipeUserName="+recipeUserName+"&recipeRate="+recipeRate+
"&recipeAmountOfRate="+recipeAmountOfRate;
URL url = new URL(link);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setChunkedStreamingMode(0);
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
int ch;
StringBuffer sb = new StringBuffer();
while ((ch = in.read()) != -1) {
sb.append((char) ch);
}
Log.e("Error", sb.toString());
} catch(Exception e) {
Log.e("Error", e.toString());
} finally {
urlConnection.disconnect();
}
}
但我得到错误:
E /错误:java.io.EOFException
为什么? 在先前的请求中,请求变得很好。 请求URL请求的时间太长了?