gpt4 book ai didi

java - 改造-IllegalArgumentException : unexpected url

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:31 26 4
gpt4 key购买 nike

我想使用 Retrofit 将视频文件(从图库中选择)上传到服务器。但它不起作用并抛出异常“java.lang.IllegalArgumentException:意外的 url:192.168.1.7”。我的代码如下所示。
PostFile.java:

public final class PostFile {
public static final MediaType MEDIA_TYPE_MARKDOWN
= MediaType.parse("vide/mp4");

private final OkHttpClient client = new OkHttpClient();

public void run(String path) throws Exception {
File file = new File(path);

Request request = new Request.Builder()
.url("192.168.1.7/")
.post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
.build();

Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

System.out.println(response.body().string());
}
}

PostFile:

public class MainActivity extends Activity {
private static int RESULT_LOAD_IMG = 1;
String decodableString;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void loadImagefromGallery(View view) {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data

Uri selectedVideo = data.getData();

String[] filePathColumn = { MediaStore.Video.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedVideo,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
decodableString = cursor.getString(columnIndex);
cursor.close();
new PostFile().run(decodableString);
Log.i("mohsen","done");
} else {
Toast.makeText(this, "You haven't picked any video",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
}

Wampserver 在我的电脑上运行 Apache Server 2.4.4。请注意,我不知道这段代码是否合理,我只是试图让它几乎盲目地工作。

最佳答案

尝试改变

    .url("192.168.1.7/")

    .url("http://192.168.1.7")

关于java - 改造-IllegalArgumentException : unexpected url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33675010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com