1
我正在開發一個Android應用程序並向我的IIS服務器發送multipart-form-data HTTP POST。我需要看到我的服務器正在接收的原始HTTP消息。爲此,在Visual Studio 2013,我把一箇中斷只是這一行檢查收到的原始HTTP消息
public String Report([Bind(Include = "lasfotos,comentario,asunto")] HttpPostedFileBase lasfotos, string comentario, string asunto)
在局部變量,我可以看到很多有關類似路徑的HTTP消息,內容lenght等,但這一>基地>要求后里面我無法找到原始HTTP的位置。
編輯:我爲什麼認爲看到原始http是一個解決方案?因爲我可以很容易地在這裏找到我的問題。但我會告訴你我的基本問題: 我有這個功能在Java中發送的數據到服務器。我可以看到「comentario」和「asunto」,而是「lasfotos」 =空
public static String Postear(ArrayList<File> files, String asunto, String detalle)
{
String respuesta;
try
{
String boundary = "qu1ckr3port_myb0undy";
String filesboundary = "boundy_4_files";
URL url = new URL("http://192.168.10.100/QuickReport/Uploads/Report");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes("--"+boundary+"\r\n" +
"Content-Disposition: form-data; name=\"lasfotos\"\r\n" +
"Content-Type: multipart/mixed; boundary="+filesboundary+"\r\n\r\n");
for (byte i = 0; i < files.size(); i++)
{
outputStream.writeBytes("--"+filesboundary+"\r\n" +
"Content-Disposition: file; filename=\"" + files.get(i).getName() + "\"\r\n" +
"Content-Type: image/jpeg\r\n\r\n");
FileInputStream fileInputStream = new FileInputStream(files.get(i));
int bytesAvailable = fileInputStream.available();
int bufferSize = Math.min(bytesAvailable, 1024 * 1024);
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, 1024 * 1024);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
fileInputStream.close();
outputStream.writeBytes("\r\n");
}
outputStream.writeBytes("--"+filesboundary+"--\r\n" +
"--"+boundary+"\r\n" +
"Content-Disposition: form-data; name=\"comentario\"\r\n\r\n" +
detalle + "\r\n" +
"--"+boundary+"\r\n");
outputStream.writeBytes("\r\n" +
"--"+boundary+"\r\n" +
"Content-Disposition: form-data; name=\"asunto\"\r\n\r\n" +
asunto + "\r\n" +
"--"+boundary+"--\r\n");
respuesta = "";
String linea;
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((linea = reader.readLine()) != null) respuesta += linea;
reader.close();
outputStream.flush();
outputStream.close();
} catch (Exception e)
{
respuesta = "error";
e.printStackTrace();
}
return respuesta;
}
'我需要看到的是我的服務器receiving.'你**需要解釋爲什麼原始的HTTP消息** 。這看起來非常像[XY問題](http://meta.stackexchange.com/a/66378/171858)。不要問我們如何獲得原始的http消息,你應該解釋什麼才能解決。 –
[Fiddler](http://www.telerik.com/fiddler)是查看此類信息的好工具 – dave
您可以在Visual Studio中獲取身體並模擬頭部。要獲得字節實際的確切字節,您需要Fiddler。我會看看我是否可以在我的代碼 – MatthewMartin