0

我有一个 php 脚本,如果用户有权限下载和图像,则图像将发送到 webbrowser,但如果用户没有权限,则显示带有信息的 xml。

代码:

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 回答