0

ユーザーがダウンロードして画像化する権限を持っている場合は画像がウェブブラウザに送信されますが、ユーザーが権限を持っていない場合は情報を含むxmlが表示されるphpスクリプトがあります。

phpcode:

if($this->can_download($user->id)){

$id = int_escape($_GET['id']);
$image = Image::by_id($id);

if(!is_null($image)) {
    $page->set_mode("data");

    $page->set_type($image->get_mime_type());
    $file = $image->get_image_filename();

    $page->set_data(file_get_contents($file));

    //WE UPDATE THAT THE USER HAS DOWNLOADED A FILE.
    $this->update_database($user->id, "download");
} else {
    $xml = "<status>\n";
    $xml .= "<info code=\"145\" message=\"Image does not exists.\"/>\n";
    $xml .= "</status>";

    $page->set_type("application/xml");
    $page->set_data($xml);
} 
}else {
    $xml = "<status>\n";
    $xml .= "<info code=\"145\" message=\"Yor has reached your daily limit.\"/>\n";
    $xml .= "</status>";

    $page->set_type("application/xml");
    $page->set_data($xml);
}

画像が保存されている場合はvb.netで応答の種類を識別したり、パーサーにxmlを送信して使用したりするにはどうすればよいですか?

これは私のvbコードです:

Dim PerformedUserUrl As String = UserUrl & "?username=" & username & _
                                             "&password=" & password

Dim WebRequest As HttpWebRequest = HttpWebRequest.Create(PerformedUserUrl)

WebRequest.Method = "GET"

Dim webResponse As HttpWebResponse = Nothing
Dim stReader As StreamReader = Nothing

Dim response as string

Try
    webResponse = WebRequest.GetResponse()
    stReader = New StreamReader(webResponse.GetResponseStream())

    response stReader.ReadToEnd()

Catch ex As Exception
    MsgBox(ex.Message)
End Try

Return response
4

1 に答える 1

1

ContentType物件 の確認はいかがですか?

「application/xml」を返す場合は、XMLである可能性があります。それ以外の場合は画像(指定したサーバー側のコードに基づく)

于 2009-12-30T18:09:02.477 に答える