小编Dam*_*les的帖子

.NET 4.6.2"值不能为空"WebRequest.GetResponse()异常

当我在.NET 4.6.2上运行以下代码时,

var req = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
req.Method = "POST";
req.ContentType = "application/json";
req.Headers.Add("Authorization", "key=my real key is here");

string json = "{\r\n  \"to\": \"/topics/news\",\r\n  \"data\": {\r\n    \"item0\": \"0\",\r\n    \"item1\": \"1\"\r\n  }\r\n}";
var jsonbytes = Encoding.UTF8.GetBytes(json);

var reqStr = req.GetRequestStream();
reqStr.Write(jsonbytes, 0, jsonbytes.Length);
reqStr.Close();

var res = (HttpWebResponse)req.GetResponse();
Debug.WriteLine(res.StatusCode);
var sr = new StreamReader(res.GetResponseStream());
Debug.Write(sr.ReadToEnd());
sr.Close();
Run Code Online (Sandbox Code Playgroud)

以下异常发生在var res = (HttpWebResponse)req.GetResponse();.

Exception   Exception thrown: 'System.ArgumentNullException' in mscorlib.dll ("Value cannot be null.")  System.ArgumentNullException
Run Code Online (Sandbox Code Playgroud)

我无法获得更多信息.我不知道什么值是null.我在.NET 4.5.2上运行了相同的代码,没有发生异常.为什么会发生这种异常?

.net c# webrequest

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

"VPN"Chrome扩展程序真的是VPN还是Web代理?

客户端问我是否可以创建可以连接到其VPN服务器的"VPN"扩展.我在Chrome网上应用店中看到了很多VPN扩展程序,但它们只影响了Chrome.VPN不会影响所有连接吗?

我找到了chrome.proxy.VPN扩展是VPN还是实际的Web代理?我可以告诉客户端他们需要设置Web代理服务器而不是VPN服务器,我chrome.proxy是否用于此目的?

vpn google-chrome-extension

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

将 Xamarin Forms 默认颜色(灰色)更改为黑色?

默认情况下,背景似乎是白色的,标签是灰色的。这看起来很糟糕。我会将标签的颜色更改为完全黑色。

但我不想单独设置 TextColor。必须有一种方法可以立即更改默认标签颜色。我查看了共享模块,但找不到任何内容。Android 项目中的 sytles.xml 没有灰色。我在哪里可以找到它?

xamarin.android xamarin xamarin.forms

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

Angular:如何将内联样式传递给组件

我创建了一个自定义组件。组件的HTML支架包含非常简单的HTML。

<!-- Generated template for the MyComponent component -->
<div>
  {{text}}
</div>
Run Code Online (Sandbox Code Playgroud)

但是添加这样的样式是行不通的。

<my-component style="height:300px; background:gray;"></my-component>
Run Code Online (Sandbox Code Playgroud)

我认为我需要将这种风格传递给人们<div>。但是如何?

ionic-framework angular

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

是否可以使用 CheckBox 设置 `error` 字符串?

对于EditText,如果我设置了error,则当用户点击 时显示字符串EditText。但是如果我设置error在 a 上CheckBox,它可以被读取吗?我尝试点击红色感叹号圆圈,但未显示该消息。

myCheckBox.error = "Can the user read this error message?"
Run Code Online (Sandbox Code Playgroud)

android android-checkbox

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

在Kotlin中实例化T型

总之,我想省略getT()下面例子中的重复.我已经读过在Kotlin中实例化一个泛型类型,但是它() -> T作为一个参数是什么意思?我该如何应用到下面?

interface Food
{
    var isHeated:Boolean;
    var name:String;
}

abstract class Cooker<T:Food>
{
    abstract fun getT():T;
    abstract fun enhance(t:T);
    fun cook(): T
    {
        var food = getT();
        food.isHeated = true;
        food.name = "heated " + food.name;
        enhance(food);
        return food;
    }
}

class PotatoChip:Food
{
    override var isHeated = false;
    override var name = "potato chip";
}

class PotatoChipCooker:Cooker<PotatoChip>()
{
    override fun getT(): PotatoChip {
        return PotatoChip();
    }
    override fun enhance(t:PotatoChip)
    {
        t.name …
Run Code Online (Sandbox Code Playgroud)

kotlin

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

为什么#ff7f7f7f 是粉红色的?

不应该是某种灰色吗?但是 FireFox 和 Chrome 都将它显示为粉红色。当我在 Paint.NET 中输入该值时,它看起来是灰色的。为什么#ff7f7f7f在网络浏览器上看起来是粉红色的?

在此处输入图片说明

在此处输入图片说明

<html><body>
<h1 style="background: #ff7f7f7f">Why does #ff7f7f7f look like this?</h1>
</body></html>
Run Code Online (Sandbox Code Playgroud)

html

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

.NET Core WPF 用户控件集设计时背景

我尝试了这个现有答案中解释的两种方法,但它们都不起作用。如何设置背景颜色?

方法一

<UserControl x:Class="deletewpf.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:deletewpf"
             mc:Ignorable="d" 
             d:DesignStyle="{StaticResource MyDesignStyle}"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <Style TargetType="{x:Type Control}" x:Key="MyDesignStyle">
            <Setter Property="Background" Value="White"/>
        </Style>
    </UserControl.Resources>    
    <Grid>
            
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

方法二

<UserControl x:Class="deletewpf.UserControl2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:deletewpf"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <d:DesignerProperties.DesignStyle>
        <Style TargetType="UserControl">
            <Setter Property="Background" Value="White"/>
        </Style>
    </d:DesignerProperties.DesignStyle>    
    <Grid>
            
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

在出现这些错误之前,我已经按下 Run 来构建它。

wpf wpf-controls .net-core visual-studio-2019

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

调整窗口大小时,在 OnPaint() 上绘制会产生残留物

我创建了一个自定义面板,用于绘制边框(包含两个矩形)。问题是,如果我调整窗口大小,仍然会有残留物……很像 Windows XP 的纸牌动画。请参阅下面的屏幕截图。我向右调整了窗口的大小。

出了什么问题,我该如何解决?

向右调整窗口大小

protected override void OnPaint(PaintEventArgs e)
{
    var outer = ClientRectangle;
    outer.Width -= 1;
    outer.Height -= 1;
    var inner = outer;
    inner.X++;
    inner.Y++;
    inner.Width -= 2;
    inner.Height -= 2;

    e.Graphics.DrawRectangle(DarkPen, outer);
    e.Graphics.DrawRectangle(WhitePen, inner);

    base.OnPaint(e);
}
Run Code Online (Sandbox Code Playgroud)

更新

一开始我以为是因为我没有删除之前绘制的矩形。于是我打电话FillRectangle删除里面。

var contentArea = inner;
contentArea.X++;
contentArea.Y++;
contentArea.Width -= 2;
contentArea.Height -= 2;
e.Graphics.FillRectangle(SystemBrushes.Control, contentArea);
Run Code Online (Sandbox Code Playgroud)

但它也不起作用。似乎控件只绘制新扩展的部分,而不是整个区域。

c# winforms

0
推荐指数
1
解决办法
285
查看次数

在不使用退出方法的情况下处理所有IDisposables?

也许我太懒了,但是using在方法中嵌套s使得该方法看起来很复杂且难以理解.是否有任何IDisposable方法可以在退出方法时由于异常而自动处理在方法中创建的所有对象?


PS.感谢您的反馈.我现在知道现在没有这样的功能.但是,从理论上讲,以下假设的语法是否合理?

void SomeMethod()
{
     autodispose var com = new SQLCommand();
     ...
     autodispose var file = new FileStream();
     ....
     autodispose var something = CreateAnObjectInAMethod(); 
     ....
}
Run Code Online (Sandbox Code Playgroud)

出于任何原因退出方法时,所有三个对象都会自动处理.

c# idisposable

0
推荐指数
1
解决办法
62
查看次数

WifiManager setWifiEnabled(),Wi-Fi 禁用后是否继续?

我想使用蜂窝数据下载文件。下载文件时似乎没有指定网络连接的API,所以我试图在下载前禁用Wi-Fi。

好像可以用这个setWifiEnabled方法,但是文档没有提到是否阻塞。我假设它不是。然后,我必须等到 Wi-Fi 被禁用才能继续下一行。

val wifiManager = this.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager.isWifiEnabled = false
(how to wait here until the system finishes disabling Wi-Fi?)
downloadFile()
Run Code Online (Sandbox Code Playgroud)

什么是最简单的方法?

android android-networking

0
推荐指数
1
解决办法
209
查看次数

为什么 #define SOMETHING TRUE 对 #if 不起作用?

以下代码打印main.cpp:20:19: note: #pragma message: serial disabled. 我原以为会打印出“enabled”。代码有什么问题吗?

int main()
{
#define SERIAL_ENABLED TRUE

#if SERIAL_ENABLED
  #pragma message "serial enabled"
#else
  #pragma message "serial disabled"
#endif

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ c-preprocessor

0
推荐指数
1
解决办法
116
查看次数

*pt +++= 20 有效吗?

下面是一道考试题。+++=看起来很奇怪,所以我问 MS Copilot,它一直说它无效,而 Google Gemini 说它可能有效,但未定义。有效*pt +++= 20;并保证与*pt++ += 20;

#include <stdio.h>
void main()
{
    int num[4] = {1, 2, 3, 4};
    int *pt = num;
    pt++;
    *pt++ = 5;
    *pt ++= 10;
    pt--;
    *pt +++= 20;
    printf("%d %d %d %d", num[0], num[1], num[2], num[3]);
}
Run Code Online (Sandbox Code Playgroud)

考试的答案是“1 5 30 4”,我在电脑上运行代码时也是这样。

c

0
推荐指数
1
解决办法
166
查看次数