小编nci*_*ite的帖子

HttpWebRequest返回"(403)Forbidden"错误

我写了一个xml抓取器来接收/解码网站上的xml文件.它主要工作正常,但它总是返回错误:

"远程服务器返回错误:(403)禁止."

对于网站http://w1.weather.gov/xml/current_obs/KSRQ.xml

我的代码是:

CookieContainer cookies = new CookieContainer();
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(Path);
webRequest.Method = "GET";
webRequest.CookieContainer = cookies;
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
    using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
    {
        string xml = streamReader.ReadToEnd();
        xmldoc.LoadXml(xml);
    }
}
Run Code Online (Sandbox Code Playgroud)

抛出GetResponse方法就是例外.我怎么知道发生了什么?

c#

9
推荐指数
2
解决办法
2万
查看次数

GDI+, 从 Graphics DrawString() 中去除空白

我对 C# GDI+ 绘制字符串函数有问题——我无法获得绘制字符串的确切大小——没有内部前导和外部前导,只有 em 高度。Microsoft 提供的字体/字符串测量 API 似乎总是输出比文本绘制大几个像素的边界框,即使在我删除了内部前导之后也是如此。

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        g.Clear(Color.Black);
        String text = "The quick brown fox jumps over the lazy dog";
        Font font = new System.Drawing.Font(FontFamily.GenericSerif, 24);
        float internalLeading = font.Size * (font.FontFamily.GetCellAscent(font.Style) + font.FontFamily.GetCellDescent(font.Style) - font.FontFamily.GetEmHeight(font.Style)) / font.FontFamily.GetEmHeight(font.Style);
        StringFormat format = StringFormat.GenericTypographic;
        format.Trimming = StringTrimming.None;
        format.FormatFlags = StringFormatFlags.NoWrap;
        System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0, pictureBox1.Width,pictureBox1.Height);
        System.Drawing.CharacterRange[] ranges = { new System.Drawing.CharacterRange(0, text.Length) };
        System.Drawing.Region[] boundings = new …
Run Code Online (Sandbox Code Playgroud)

c# gdi+

5
推荐指数
1
解决办法
1569
查看次数

Delphi的稳定FTP客户端组件?

我需要一个能够24/7稳定运行的ftp客户端.它需要在Windows XP中运行并支持Delphi.如果它支持SFTP会很好.我们之前尝试过Indy和Smart Ftp客户端.我们使用的Indy版本似乎偶尔会出现内存泄漏问题和Smart Ftp DLL崩溃.好吧,我的程序需要整天每20分钟(或更少)唤醒ftp客户端,这些FTP客户端组件最终会崩溃/冻结.这里有人能推荐我一个非常稳定的FTP客户端组件吗?非常感谢你!

delphi ftp

2
推荐指数
1
解决办法
6846
查看次数

标签 统计

c# ×2

delphi ×1

ftp ×1

gdi+ ×1