小编use*_*342的帖子

Invoke-Restmethod:我如何获得返回码?

有没有办法Invoke-RestMethod在PowerShell中调用时将返回代码存储在某处?

我的代码看起来像这样:

$url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/Adventure?key=MyKeyGoesHere"

$XMLReturned = Invoke-RestMethod -Uri $url -Method Get;
Run Code Online (Sandbox Code Playgroud)

我没有看到我的$XMLReturned变量中的任何地方返回代码为200.我在哪里可以找到返回代码?

api powershell

27
推荐指数
3
解决办法
3万
查看次数

在Java中将base64字符串转换为Image

我有一个图像通过JSON字符串发送给我.我想将该字符串转换为我的Android应用程序中的图像,然后显示该图像.

JSON字符串如下所示:

"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVI..."
Run Code Online (Sandbox Code Playgroud)

注意:我用...截断了字符串

我有一个函数(我认为)将字符串转换为图像.我这样做了吗?

public Bitmap ConvertToImage(String image){
    try{
        InputStream stream = new ByteArrayInputStream(image.getBytes());
        Bitmap bitmap = BitmapFactory.decodeStream(stream);                 
        return bitmap;  
    }
    catch (Exception e) {
        return null;            
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试在我的Android活动上显示它

String image = jsonObject.getString("barcode_img");         
Bitmap myBitmap = this.ConvertToImage(image);
ImageView cimg = (ImageView)findViewById(R.id.imageView1);

//Now try setting dynamic image
cimg.setImageBitmap(myBitmap);
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,什么都没有出现.我没有在logcat中得到任何错误.我究竟做错了什么?

谢谢

java android image

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

硬编码密码进入powershells"New-PSSession"

我有一个脚本来为给定用户在其他计算机上获取和设置用户的Windows环境变量.是否可以为该用户硬编码密码,这样我每次运行脚本时都不必输入密码?

我的脚本看起来像这样:

$s5 = New-PSSession -computername testauto2, testauto3 -Credential
Domain\testautouser

invoke-command -session $s5[0] -scriptblock {[Environment]::GetEnvironmentVariable("TestBrowser", "user")}
Run Code Online (Sandbox Code Playgroud)

passwords powershell

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

从powershell删除SQL Server数据库

我在本地计算机上有一个SQL Server实例.\SC.我想使用PowerShell脚本从该实例中删除数据库.我需要sa用户登录我的数据库.

这是我到目前为止的代码,但它不起作用:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$srv = new-object Microsoft.SqlServer.Management.Smo.Server(".\SC")
$conContext = $srv.ConnectionContext
$conContext.LoginSecure = $FALSE
$conContext.Login = "sa"
$conContext.Password = "MyPlainTextPass"
$srv2 = new-object Microsoft.SqlServer.Management.Smo.Server($conContext)
$srv2.Databases
Run Code Online (Sandbox Code Playgroud)

最后一行应该列出我的SQL实例中的数据库......但它给了我这个错误:

尝试枚举集合时发生以下异常:"无法连接到服务器.\ SC.".在行:1 char:1 + $ srv2.Databases + ~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],ExtendedTypeSystemException + FullyQualifiedErrorId:ExceptionInGetEnumerator

我究竟做错了什么?

sql-server powershell database-administration

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

Powershell命令可以将断开连接的用户从服务器上移开

是否有一个powershell命令,我可以用来将"断开连接"的用户从服务器上踢掉?一旦我知道了单个用户的单行,我就可以编写脚本.

例如,我想踢下面对话框中看到的8个用户.

在此输入图像描述

powershell windows-server-2008

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

GCP容器推送不起作用 - "拒绝:请在云控制台中启用Google容器注册表API ..."

我将docker镜像上传到GCP Container注册表时遇到问题.我按照这里说明.

正如您在下面的屏幕截图中看到的,我:

  1. 登录我的谷歌云外壳并通过dockerfile构建了一个docker镜像
  2. 正确标记我的图像(我认为)
  3. 尝试使用正确的命令推送图像(我认为)

Docker推送到GCP截图

但是,我收到了这个错误:拒绝:

Please enable Google Container Registry API in Cloud Console at https://console.cloud.google.com/apis/api/containerregistry.googleapis.com/overview?project=bentestproject-184220 before performing this operation.
Run Code Online (Sandbox Code Playgroud)

当我关注该链接时,它会将我带到错误的项目:

在此输入图像描述

当我选择自己的项目时,我可以看到确实启用了"Google Container Registry API":

在此输入图像描述

如何上传我的泊坞窗图片?

docker google-cloud-platform gcp

7
推荐指数
2
解决办法
2482
查看次数

SpringbootTest + TestContainers: how do I refresh the database after tests pollute the database

I am using an abstract class like this:

@SpringBootTest(classes = MyAppApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public abstract class AbstractIntegrationTest {

    static {
        PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer().withPassword("password")
                .withUsername("postgres").withDatabaseName("MyApp");
        postgreSQLContainer.start();

        System.setProperty("spring.datasource.url", postgreSQLContainer.getJdbcUrl());
        System.setProperty("spring.datasource.password", postgreSQLContainer.getPassword());
        System.setProperty("spring.datasource.username", postgreSQLContainer.getUsername());

    }
Run Code Online (Sandbox Code Playgroud)

Then I have many tests that leverage that use that class like this:

public class moreTests extends AbstractIntegrationTest {

    TestRestTemplate restTemplate = new TestRestTemplate("my-user", "password"); 
    HttpHeaders headers = new HttpHeaders();

    @Test
    public void SimpleHealthCheck() {    
        HttpEntity<String> entity = new HttpEntity<String>(null, headers);    
        ResponseEntity<String> response = …
Run Code Online (Sandbox Code Playgroud)

postgresql spring-boot spring-boot-test testcontainers

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

Robotium:如何在继续之前等待加载完成?

我想为Android应用程序编写Robotium/Junit测试.在某些步骤中,我希望我的测试等到旋转加载符号从屏幕上消失.

我怎样才能做到这一点?

java junit android robotium

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

使用来自互联网的图像更新android小部件(使用异步任务)

我有一个简单的Android小部件,我想用互联网上的图像更新.我可以在小部件上显示静态图像没问题.我被告知你需要使用异步任务,我对这些没有多少经验.

这是我的小部件:

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {

        super.onUpdate(context, appWidgetManager, appWidgetIds);

        for (int i = 0; i < appWidgetIds.length; i++){
            int appWidgetId = appWidgetIds[i];      

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);

                //Setup a static image, this works fine.
            views.setImageViewResource(R.id.imageView1, R.drawable.wordpress_icon);             

            new DownloadBitmap().execute("MyTestString");       

            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
Run Code Online (Sandbox Code Playgroud)

然后我有一个异步任务类来进行下载.它看起来像这样:

public class DownloadBitmap extends AsyncTask<String, Void, Bitmap> {

    /** The url from where to download the image. */
    private String url = "http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg"; 

    @Override
    protected Bitmap doInBackground(String... params) {
        try { …
Run Code Online (Sandbox Code Playgroud)

android widget android-asynctask

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

psexec不被承认

我正在使用Microsoft Server 2008计算机.出于某种原因,命令"psexec"在这台1台机器上的PowerShell中无效.

当我尝试运行它时,我得到了这个:

PS C:\> psexec
The term 'psexec' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:7
+ psexec <<<<
    + CategoryInfo          : ObjectNotFound: (psexec:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\>
Run Code Online (Sandbox Code Playgroud)

它正在运行powershell 2.0.我发现这一点:

PS C:\> $Host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0 …
Run Code Online (Sandbox Code Playgroud)

powershell psexec

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

在C#中设置/获取命令行系统变量

当我打开一个Windows命令提示符并输入"set"然后输入时,我得到一个系统变量列表.

如何使用visual studio在C#中设置/获取它们?

我试过了:

System.Environment.SetEnvironmentVariable("TestVariableName", "test123");
Run Code Online (Sandbox Code Playgroud)

但是,当我在命令行中输入"set"时,我没有看到名为"TestVariableName"的新变量,其值为"test123".

我究竟做错了什么?

谢谢

c# variables command-line system

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

Powershell运行SQL作业,延迟,然后运行下一个

我正在编写一个Powershell脚本,它使用本地SQL Server数据库执行多项操作.

我正在做的一件事是一个接一个地运行几个SQL作业.我像这样运行它们:

 sqlcmd -S .\ -Q "EXECUTE msdb.dbo.sp_start_job @job_name = 'Rebuild Content Asset Relationship Data'"
Run Code Online (Sandbox Code Playgroud)

有没有办法让Powershell延迟运行下一个工作,直到完成第一个工作?

谢谢

sql-server powershell

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