- Katılım
- 30 Ocak 2019
- Mesajlar
- 21.093
- Makaleler
- 9
- Çözümler
- 222
Daha fazla
- Cinsiyet
- Erkek
C#:
static readonly HttpClient client = new HttpClient();
public static string path = @"C:\Users\***\Downloads\steam.jpg";
const string api = "api/upload/";
public static async Task<bool> Upload()
{
using MultipartFormDataContent multipartContent = new();
var imageContent = new StreamContent(File.OpenRead(path));
imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Image.Jpeg);
StringContent str = new StringContent("type".ToString());
multipartContent.Add(str, "test");
multipartContent.Add(imageContent, "file", Path.GetFileName(path));
using var response = await client.PostAsync(api, multipartContent);
string message = await response.Content.ReadAsStringAsync();
MessageBox.Show(message);
return true;
}
PHP:
if (isset($_FILES["file"]) && isset($_POST["type"])){
$type = $_POST["type"];
$file = $_FILES["file"];
var_dump($type);
var_dump($file);
}
Bu iki kodu kullanarak C#'dan veri göndermeye çalışıyorum. Eğer "isset($_POST["type"]" kısmını kaldırırsam sıkıntı çözülüyor. Ancak ben "type"ın "test" olduğunu belirttim kodda. Neden veri gelmiyor?
@Eray T Fikrin var mı?