S
shershun4ik
Есть у меня вот такой вот код:
В ответ я получаю statusCode1 = 400 (BadRequest). Что я делаю не так?
Код:
package sendfile;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.Credentials;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class SendFile {
private static String url = "http://localhost:7000/FileUpload.ashx?basic=1";
public static void main(String[] args) throws IOException {
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);
client.setConnectionTimeout(8000);
Credentials defaultcreds = new UsernamePasswordCredentials("USER", "**********");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
// Send any file as the body of the POST request
File f = new File("D:/MediaID.bin");
System.out.println("File Length = " + f.length());
postMethod.setRequestBody(new FileInputStream(f));
postMethod.setRequestHeader("Content-type", "application/octet-stream");
postMethod.setRequestHeader("clientGuid", "06d8f57f-2c3e-4225-98f8-b1f02ff08a77");
postMethod.setRequestHeader("value", "128");
postMethod.setRequestHeader("FileName", "MediaID.bin");
int statusCode1 = client.executeMethod(postMethod);
System.out.println("statusLine>>>" + postMethod.getStatusLine());
postMethod.releaseConnection();
}
}
В ответ я получаю statusCode1 = 400 (BadRequest). Что я делаю не так?