如果img src不包含图像文件名,则无法使用WebClient读取图像



我正在尝试使用WebClient下载图像。图像源不包含图像文件的路径,而是包含一个参数如下的查询">

src="getphoto.action?memberInfo.memberNumber=123" alt="no image"

我的WebClient返回HTML而不是图像。返回的HTML以开头

<!-- Header Begin -->
<!DOCTYPE html>
<head >
<title> 
Technical Error
</title>

最有可能的是,图像是根据成员ID从数据库中动态获取的。当我在Chrome DevTools中指向图像的src时,Chrome成功地显示了图像缩略图。

为什么我无法从其src属性中获取图像?

1(您可以使用Ajax javascript来获取带有html的页面。您可以解释从该页面传入的请求,并从html代码中提取图像。类似这样的东西:

//here include Jquery for more detail go to W3school jquery
var pageid=1
var url="getphoto.action?memberInfo.memberNumber="+pageid;
$.ajax({
url: url, 
success: function(result){
//here interpret the html code incoming to  extract the page
//you can use Jquery or Javascript
}});

2( 或者您可以尝试使用iframe来显示该图像

<iframe src=""></iframe>

最新更新