putlokcer Web サイトのアップローダー クラスを作成しようとしていますが、API サポートがあります。
彼らのドキュメントによると、彼らは次のようにアップロードの例を示しました
// Variables to Post
$local_file = "/path/to/filename.avi";
$file_to_upload = array(
'file'=>'@'.$local_file,
'convert'=>'1', //optional Argument
'user'=>'YOUR_USERNAME',
'password'=>'YOUR_PASSWORD',
'folder'=>'FOLDER_NAME' // Optional Argument
);
// Do Curl Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://upload.putlocker.com/uploadapi.php');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file_to_upload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec ($ch);
curl_close ($ch);
// Do Stuff with Results
echo $result;
今、次のように java.net パッケージを使用して Java の観点から変換しようとしています。
BufferedInputStream bis = null; BufferedOutputStream bos = null; { URL url = 新しい URL("http://upload.putlocker.com/uploadapi.php"); を試してください。URLConnection uc = url.openConnection(); uc.setDoOutput(真); uc.setDoInput(真); uc.setAllowUserInteraction(偽);
bos = new BufferedOutputStream(uc.getOutputStream());
bis = new BufferedInputStream(new FileInputStream("C:\\Dinesh\\Naruto.jpg"));
int i;
bos.write("file".getBytes());
// read byte by byte until end of stream
while ((i = bis.read()) != -1) {
bos.write(i);
}
bos.write("user=myusername".getBytes());
bos.write("password=mypassword".getBytes());
br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String k = "",tmp="";
while ((tmp = br.readLine()) != null) {
System.out.println(tmp);
k += tmp;
}
} catch (Exception e) {
System.out.println(e);
}
「有効なログインまたはファイルが渡されませんでした」という応答が返ってきました。これは、HTTP POST 要求が有効な投稿フィールドで送信されていないことを意味します。
java.netパッケージでこれを機能させる方法を誰かに説明してもらえますか?